当前位置: 首页>>代码示例>>C#>>正文


C# AssemblyBuilder.AddCodeCompileUnit方法代码示例

本文整理汇总了C#中System.Web.Compilation.AssemblyBuilder.AddCodeCompileUnit方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyBuilder.AddCodeCompileUnit方法的具体用法?C# AssemblyBuilder.AddCodeCompileUnit怎么用?C# AssemblyBuilder.AddCodeCompileUnit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Compilation.AssemblyBuilder的用法示例。


在下文中一共展示了AssemblyBuilder.AddCodeCompileUnit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateCode

 public override void GenerateCode(AssemblyBuilder assemblyBuilder)
 {
     if (this.Parser.RequiresCompilation)
     {
         BaseCodeDomTreeGenerator generator = this.CreateCodeDomTreeGenerator(this._parser);
         CodeCompileUnit ccu = generator.GetCodeDomTree(assemblyBuilder.CodeDomProvider, assemblyBuilder.StringResourceBuilder, base.VirtualPathObject);
         if (ccu != null)
         {
             if (this._parser.AssemblyDependencies != null)
             {
                 foreach (Assembly assembly in (IEnumerable) this._parser.AssemblyDependencies)
                 {
                     assemblyBuilder.AddAssemblyReference(assembly, ccu);
                 }
             }
             assemblyBuilder.AddCodeCompileUnit(this, ccu);
         }
         this._instantiatableFullTypeName = generator.GetInstantiatableFullTypeName();
         if (this._instantiatableFullTypeName != null)
         {
             assemblyBuilder.GenerateTypeFactory(this._instantiatableFullTypeName);
         }
         this._intermediateFullTypeName = generator.GetIntermediateFullTypeName();
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:25,代码来源:BaseTemplateBuildProvider.cs

示例2: GenerateCode

    public override void GenerateCode(AssemblyBuilder assemblyBuilder) {

        CodeCompileUnit codeCompileUnit = _parser.GetCodeModel();

        // Bail if we have nothing we need to compile
        if (codeCompileUnit == null)
            return;

        assemblyBuilder.AddCodeCompileUnit(this, codeCompileUnit);

        // Add all the assemblies
        if (_parser.AssemblyDependencies != null) {
            foreach (Assembly assembly in _parser.AssemblyDependencies) {
                assemblyBuilder.AddAssemblyReference(assembly, codeCompileUnit);
            }
        }

        // NOTE: we can't actually generate the fast factory because it would give
        // a really bad error if the user specifies a classname which doesn't match
        // the actual class they define.  A bit unfortunate, but not that big a deal...

        // tell the host to generate a fast factory for this type (if any)
        //string generatedTypeName = _parser.GeneratedTypeName;
        //if (generatedTypeName != null)
        //    assemblyBuilder.GenerateTypeFactory(generatedTypeName);
    }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:26,代码来源:SimpleHandlerBuildProvider.cs

示例3: GenerateCodeCore

        void GenerateCodeCore(AssemblyBuilder assemblyBuilder)
        {
            if (assemblyBuilder == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("assemblyBuilder");
            }

            CodeCompileUnit codeCompileUnit = parser.GetCodeModel();

            // Bail if we have nothing we need to compile
            //
            if (codeCompileUnit == null)
                return;

            // Add the code unit and then add all the assemblies 
            //
            assemblyBuilder.AddCodeCompileUnit(this, codeCompileUnit);
            if (parser.AssemblyDependencies != null)
            {
                foreach (Assembly assembly in parser.AssemblyDependencies)
                {
                    assemblyBuilder.AddAssemblyReference(assembly);
                }
            }
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:25,代码来源:ServiceBuildProvider.cs

示例4: GenerateCode

 public override void GenerateCode(AssemblyBuilder assemblyBuilder)
 {
     assemblyBuilder.AddAssemblyReference(typeof(SimpleWeb).Assembly);
     assemblyBuilder.AddAssemblyReference(typeof(SimpleTemplateBase).Assembly);
     assemblyBuilder.AddCodeCompileUnit(this, GeneratedCode);
     assemblyBuilder.GenerateTypeFactory(String.Format(CultureInfo.InvariantCulture, "{0}.{1}", Host.DefaultNamespace, "Foot"));
 }
开发者ID:rkevinstout,项目名称:Simple.Web,代码行数:7,代码来源:SimpleRazorBuildProvider.cs

示例5: GenerateCode

        public override void GenerateCode(AssemblyBuilder myAb)
        {
            XmlDocument carXmlDoc = new XmlDocument();

            using (Stream passedFile = OpenStream())
            {
                carXmlDoc.Load(passedFile);
            }
            XmlNode mainNode = carXmlDoc.SelectSingleNode("/car");
            string selectionMainNode = mainNode.Attributes["name"].Value;

            XmlNode colorNode = carXmlDoc.SelectSingleNode("/car/color");
            string selectionColorNode = colorNode.InnerText;

            XmlNode doorNode = carXmlDoc.SelectSingleNode("/car/door");
            string selectionDoorNode = doorNode.InnerText;

            XmlNode speedNode = carXmlDoc.SelectSingleNode("/car/speed");
            string selectionSpeedNode = speedNode.InnerText;

            CodeCompileUnit ccu = new CodeCompileUnit();
            CodeNamespace cn = new CodeNamespace();
            CodeMemberProperty cmp1 = new CodeMemberProperty();
            CodeMemberProperty cmp2 = new CodeMemberProperty();
            CodeMemberMethod cmm1 = new CodeMemberMethod();

            cn.Imports.Add(new CodeNamespaceImport("System"));

            cmp1.Name = "Color";
            cmp1.Type = new CodeTypeReference(typeof(string));
            cmp1.Attributes = MemberAttributes.Public;
            cmp1.GetStatements.Add(new CodeSnippetExpression("return \"" +
               selectionColorNode + "\""));

            cmp2.Name = "Doors";
            cmp2.Type = new CodeTypeReference(typeof(int));
            cmp2.Attributes = MemberAttributes.Public;
            cmp2.GetStatements.Add(new CodeSnippetExpression("return " +
               selectionDoorNode));

            cmm1.Name = "Go";
            cmm1.ReturnType = new CodeTypeReference(typeof(int));
            cmm1.Attributes = MemberAttributes.Public;
            cmm1.Statements.Add(new CodeSnippetExpression("return " +
               selectionSpeedNode));

            CodeTypeDeclaration ctd = new CodeTypeDeclaration(selectionMainNode);
            ctd.Members.Add(cmp1);
            ctd.Members.Add(cmp2);
            ctd.Members.Add(cmm1);

            cn.Types.Add(ctd);
            ccu.Namespaces.Add(cn);

            myAb.AddCodeCompileUnit(this, ccu);
        }
开发者ID:kacecode,项目名称:SchoolWork,代码行数:56,代码来源:Car.cs

示例6: GenerateCode

        /// <summary>
        /// Generates source code for the virtual path of the build provider, and adds the source code to a specified assembly builder.
        /// </summary>
        /// <param name="assemblyBuilder">The assembly builder that references the source code generated by the build provider.</param>
        public override void GenerateCode(AssemblyBuilder assemblyBuilder)
        {
            Utility.WriteTrace("Invoking BuildProvider");
            DataService.LoadProviders();
            ICodeLanguage language = new CSharpCodeLanguage();

            DirectoryInfo di = new DirectoryInfo(HostingEnvironment.ApplicationPhysicalPath + "\\App_Code");
            FileInfo[] fi = di.GetFiles("*.vb");
            if(fi.Length > 0)
                language = new VBCodeLanguage();

            StringBuilder code = new StringBuilder(language.DefaultUsingStatements);
            TurboCompiler tc = new TurboCompiler();

            // loop over the providers, and generate code for each
            foreach(DataProvider provider in DataService.Providers)
            {
                Utility.WriteTrace(String.Format("Creating code for {0}", provider.Name));
                string[] tableList = DataService.GetTableNames(provider.Name);
                string[] viewList = DataService.GetViewNames(provider.Name);

                foreach(string tbl in tableList)
                {
                    TurboTemplate tt = CodeService.BuildClassTemplate(tbl, language, provider);
                    tc.AddTemplate(tt);
                    if(provider.GenerateODSControllers)
                    {
                        TurboTemplate tODS = CodeService.BuildODSTemplate(tbl, language, provider);
                        tc.AddTemplate(tODS);
                    }
                }

                foreach(string view in viewList)
                {
                    TurboTemplate tt = CodeService.BuildViewTemplate(view, language, provider);
                    tc.AddTemplate(tt);
                }

                tc.AddTemplate(CodeService.BuildSPTemplate(language, provider));
            }

            if(DataService.Providers.Count > 0)
                tc.AddTemplate(CodeService.BuildStructsTemplate(language, DataService.Provider));

            foreach(TurboTemplate tt in tc.Templates)
                tt.AddUsingBlock = false;
            tc.Run();

            foreach(TurboTemplate tt in tc.Templates)
                code.Append(tt.FinalCode);

            assemblyBuilder.AddCodeCompileUnit(this, new CodeSnippetCompileUnit(code.ToString()));
        }
开发者ID:khurram063,项目名称:SubSonic-2.0,代码行数:57,代码来源:BuildProvider.cs

示例7: GenerateCode

        public override void GenerateCode(AssemblyBuilder assemblyBuilder)
        {
            if (this._generatedCode == null)
            {
                this._generatedCode = GenerateCode();
            }

            assemblyBuilder.AddAssemblyReference(typeof(SimpleWeb).Assembly);
            assemblyBuilder.AddAssemblyReference(typeof(SimpleTemplateBase).Assembly);
            assemblyBuilder.AddCodeCompileUnit(this, this._generatedCode);
            assemblyBuilder.GenerateTypeFactory(this._typeName);
        }
开发者ID:muratbeyaztas,项目名称:Simple.Web,代码行数:12,代码来源:SimpleRazorBuildProvider.cs

示例8: GenerateCode

		/// <summary>
		/// Generates source code for the virtual path of the build provider, and adds the source code to a specified assembly builder.
		/// </summary>
		/// <param name="assemblyBuilder">The assembly builder that references the source code generated by the build provider.</param>
		public override void GenerateCode(AssemblyBuilder assemblyBuilder)
		{
            try
            {
                assemblyBuilder.AddCodeCompileUnit(this, this.GetGeneratedCode());

                assemblyBuilder.GenerateTypeFactory(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", new object[] { this.host.DefaultNamespace, this.host.DefaultClassName }));
            }
            catch (Exception ex)
            {
                Log.Error("GenerateCode(): ", ex);
            }
        }
开发者ID:grammarware,项目名称:fodder,代码行数:17,代码来源:src_ServiceStack_Razor_CSharpRazorBuildProvider.cs

示例9: GenerateCode

 public override void GenerateCode(AssemblyBuilder assemblyBuilder)
 {
     CodeCompileUnit codeModel = this._parser.GetCodeModel();
     if (codeModel != null)
     {
         assemblyBuilder.AddCodeCompileUnit(this, codeModel);
         if (this._parser.AssemblyDependencies != null)
         {
             foreach (Assembly assembly in this._parser.AssemblyDependencies)
             {
                 assemblyBuilder.AddAssemblyReference(assembly, codeModel);
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:15,代码来源:SimpleHandlerBuildProvider.cs

示例10: GenerateCode

        public override void GenerateCode(AssemblyBuilder assemblyBuilder)
        {
            // look at the assembly builder to see which language we should use in the App_Code directory
            EntityCodeGenerator generator = null;
            if (assemblyBuilder.CodeDomProvider.FileExtension.ToLowerInvariant() == "cs")
            {
                generator = new EntityCodeGenerator(LanguageOption.GenerateCSharpCode);
            }
            else
            {
                generator = new EntityCodeGenerator(LanguageOption.GenerateVBCode);
            }

            // generate the code for our CSDL file
            IList<EdmSchemaError> errors = null;
            using (XmlReader input = XmlReader.Create(VirtualPathProvider.OpenFile(base.VirtualPath)))
            {
                using (StringWriter output = new StringWriter(CultureInfo.InvariantCulture))
                {
                    // Read from input and generate into output, put errors in a class member
                    var entityFrameworkVersion = GetEntityFrameworkVersion(BuildManager.TargetFramework.Version);
                    errors = generator.GenerateCode(input, output, entityFrameworkVersion);
                    if (errors.Count == 0)
                    {
                        output.Flush();
                        assemblyBuilder.AddCodeCompileUnit(this, new CodeSnippetCompileUnit(output.ToString()));
                    }
                }
            }

            // if there are errors, package this data into XmlExceptions and throw this
            // if we are in VS, the ASP .NET stack will place this information in the error pane
            // if we are in the ASP .NET runtime, it will use this information to build the error page
            if (errors != null && errors.Count > 0)
            {
                XmlException inner = null;
                XmlException outer = null;
                foreach (EdmSchemaError error in errors)
                {
                    outer = new XmlException(error.Message, inner, error.Line, error.Column);
                    inner = outer;
                }

                throw outer;
            }

            BuildProviderUtils.AddArtifactReference(assemblyBuilder, this, base.VirtualPath);
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:48,代码来源:EntityModelBuildProvider.cs

示例11: GenerateCode

		public override void GenerateCode (AssemblyBuilder assemblyBuilder)
		{
			CodeCompileUnit unit = new CodeCompileUnit ();
			CodeNamespace dataSetCode = new CodeNamespace(null);
			unit.Namespaces.Add (dataSetCode);
			
			string path = HttpContext.Current.Request.MapPath (VirtualPath);
			TextReader tr = new StreamReader (path);
			
			CodeDomProvider provider = assemblyBuilder.CodeDomProvider;
			if (provider == null)
				throw new HttpException ("Assembly builder has no code provider");

			System.Data.Design.TypedDataSetGenerator.Generate (tr.ReadToEnd (), unit, dataSetCode, provider);

			assemblyBuilder.AddCodeCompileUnit (unit);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:17,代码来源:XsdBuildProvider.cs

示例12: GenerateCode

    public override void GenerateCode(AssemblyBuilder assemblyBuilder)  {
#if !FEATURE_PAL // FEATURE_PAL does not support System.Configuration.Design
        CodeCompileUnit codeCompileUnit = new CodeCompileUnit();

        // Process the .settings file and generate a CodeCompileUnit from it
        using (Stream stream = VirtualPathProvider.OpenFile(VirtualPath)) {
            using (TextReader reader = new StreamReader(stream)) {
                SettingsSingleFileGenerator.Generate(
                    reader, codeCompileUnit, assemblyBuilder.CodeDomProvider, TypeAttributes.Public);
            }
        }

        // Add the CodeCompileUnit to the compilation
        assemblyBuilder.AddCodeCompileUnit(this, codeCompileUnit);
#else   // !FEATURE_PAL 
        throw new NotImplementedException("System.Configuration.Design - ROTORTODO");
#endif  // !FEATURE_PAL 
    }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:18,代码来源:SettingsBuildProvider.cs

示例13: GenerateCode

    public override void GenerateCode(AssemblyBuilder assemblyBuilder)  {

        // Get the namespace that we will use
        string ns = Util.GetNamespaceFromVirtualPath(VirtualPathObject);

        ServiceDescription sd;

        // Load the wsdl file
        using (Stream stream = VirtualPathObject.OpenFile()) {
            try {
                sd = ServiceDescription.Read(stream);
            }
            catch (InvalidOperationException e) {
                // It can throw an InvalidOperationException, with the relevant
                // XmlException as the inner exception.  If so, throw that instead.
                XmlException xmlException = e.InnerException as XmlException;
                if (xmlException != null)
                    throw xmlException;
                throw;
            }
        }

        ServiceDescriptionImporter importer = new ServiceDescriptionImporter();

#if !FEATURE_PAL
        importer.CodeGenerator = assemblyBuilder.CodeDomProvider;

        importer.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties |
            CodeGenerationOptions.GenerateNewAsync | CodeGenerationOptions.GenerateOldAsync;
#endif // !FEATURE_PAL
        importer.ServiceDescriptions.Add(sd);

        CodeCompileUnit codeCompileUnit = new CodeCompileUnit();

        CodeNamespace codeNamespace = new CodeNamespace(ns);
        codeCompileUnit.Namespaces.Add(codeNamespace);

        // Create the code compile unit
        importer.Import(codeNamespace, codeCompileUnit);

        // Add the CodeCompileUnit to the compilation
        assemblyBuilder.AddCodeCompileUnit(this, codeCompileUnit);
    }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:43,代码来源:WsdlBuildProvider.cs

示例14: GenerateCode

 public override void GenerateCode(AssemblyBuilder assemblyBuilder)
 {
     string namespaceFromVirtualPath = Util.GetNamespaceFromVirtualPath(base.VirtualPathObject);
     XmlDocument document = new XmlDocument();
     using (Stream stream = base.OpenStream())
     {
         document.Load(stream);
     }
     string outerXml = document.OuterXml;
     CodeCompileUnit compileUnit = new CodeCompileUnit();
     CodeNamespace namespace2 = new CodeNamespace(namespaceFromVirtualPath);
     compileUnit.Namespaces.Add(namespace2);
     if (CompilationUtil.IsCompilerVersion35OrAbove(assemblyBuilder.CodeDomProvider.GetType()))
     {
         TypedDataSetGenerator.GenerateOption none = TypedDataSetGenerator.GenerateOption.None;
         none |= TypedDataSetGenerator.GenerateOption.HierarchicalUpdate;
         none |= TypedDataSetGenerator.GenerateOption.LinqOverTypedDatasets;
         Hashtable customDBProviders = null;
         TypedDataSetGenerator.Generate(outerXml, compileUnit, namespace2, assemblyBuilder.CodeDomProvider, customDBProviders, none);
     }
     else
     {
         TypedDataSetGenerator.Generate(outerXml, compileUnit, namespace2, assemblyBuilder.CodeDomProvider);
     }
     if (TypedDataSetGenerator.ReferencedAssemblies != null)
     {
         bool flag2 = CompilationUtil.IsCompilerVersion35(assemblyBuilder.CodeDomProvider.GetType());
         foreach (Assembly assembly in TypedDataSetGenerator.ReferencedAssemblies)
         {
             if (flag2)
             {
                 AssemblyName name = assembly.GetName();
                 if (name.Name == "System.Data.DataSetExtensions")
                 {
                     name.Version = new Version(3, 5, 0, 0);
                     CompilationSection.RecordAssembly(name.FullName, assembly);
                 }
             }
             assemblyBuilder.AddAssemblyReference(assembly);
         }
     }
     assemblyBuilder.AddCodeCompileUnit(this, compileUnit);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:43,代码来源:XsdBuildProvider.cs

示例15: GenerateCode

    /// <summary>
    /// 此方法已被重写以产生代码
    /// </summary>
    /// <param name="assemblyBuilder">程序集构建器</param>
    public override void GenerateCode( AssemblyBuilder assemblyBuilder )
    {

      if ( _type == null )
      {
        _type = CreateDocumentProviderType();
      }

      var @namespace = new CodeNamespace( "HTML" );
      @namespace.Types.Add( _type );

      var unit = new CodeCompileUnit();
      unit.Namespaces.Add( @namespace );

      assemblyBuilder.AddCodeCompileUnit( this, unit );

      AddReferences( assemblyBuilder );

    }
开发者ID:ajayumi,项目名称:Jumony,代码行数:23,代码来源:HtmlBuildProvider.cs


注:本文中的System.Web.Compilation.AssemblyBuilder.AddCodeCompileUnit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。