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


C# AssemblyBuilder.GenerateTypeFactory方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: GenerateCode

    public override void GenerateCode(AssemblyBuilder assemblyBuilder) {

        // Don't generate any code for no-compile pages
        if (!Parser.RequiresCompilation)
            return;

        BaseCodeDomTreeGenerator treeGenerator = CreateCodeDomTreeGenerator(_parser);

        CodeCompileUnit ccu = treeGenerator.GetCodeDomTree(assemblyBuilder.CodeDomProvider,
            assemblyBuilder.StringResourceBuilder, VirtualPathObject);

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

            assemblyBuilder.AddCodeCompileUnit(this, ccu);
        }

        // Get the name of the generated type that can be instantiated.  It may be null
        // in updatable compilation scenarios.
        _instantiatableFullTypeName = treeGenerator.GetInstantiatableFullTypeName();

        // tell the assembly builder to generate a fast factory for this type
        if (_instantiatableFullTypeName != null)
            assemblyBuilder.GenerateTypeFactory(_instantiatableFullTypeName);

        _intermediateFullTypeName = treeGenerator.GetIntermediateFullTypeName();
    }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:32,代码来源:BaseTemplateBuildProvider.cs

示例6: GenerateCode

        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////

        // BuildProvider implementation

        public override void GenerateCode(AssemblyBuilder assemblyBuilder) {
            Hashtable           properties   = ProfileBase.GetPropertiesForCompilation();
            CodeCompileUnit     compileUnit  = new CodeCompileUnit();
            Hashtable           groups       = new Hashtable();
            Type                baseType     = Type.GetType(ProfileBase.InheritsFromTypeString, false);

            // namespace ASP {
            //
            CodeNamespace ns = new CodeNamespace();
            // ns.Name = BaseCodeDomTreeGenerator.defaultNamespace;

            //GEN: using System;
            ns.Imports.Add(new CodeNamespaceImport("System"));
            //GEN: using System.Web;
            ns.Imports.Add(new CodeNamespaceImport("System.Web"));
            //GEN: using System.Web.Profile;
            ns.Imports.Add(new CodeNamespaceImport("System.Web.Profile"));

            // class Profile :  System.Web.Security.ProfileBase {
            //
            CodeTypeDeclaration type = new CodeTypeDeclaration();
            type.Name = ProfileTypeName;
            if (baseType != null) {
                type.BaseTypes.Add(new CodeTypeReference(baseType));
                assemblyBuilder.AddAssemblyReference(baseType.Assembly, compileUnit);
            } else {
                type.BaseTypes.Add(new CodeTypeReference(ProfileBase.InheritsFromTypeString));
                ProfileSection config = MTConfigUtil.GetProfileAppConfig();
                if (config != null) {
                    PropertyInformation prop = config.ElementInformation.Properties["inherits"];
                    if (prop != null && prop.Source != null && prop.LineNumber > 0)
                        type.LinePragma = new CodeLinePragma(HttpRuntime.GetSafePath(prop.Source), prop.LineNumber);
                }
            }
            // tell the assemblyBuilder to generate a fast factory for this type
            assemblyBuilder.GenerateTypeFactory(/*ns.Name + "." + */ ProfileTypeName);

            foreach(DictionaryEntry de in properties)
            {
                ProfileNameTypeStruct property = (ProfileNameTypeStruct)de.Value;
                if (property.PropertyType != null)
                    assemblyBuilder.AddAssemblyReference(property.PropertyType.Assembly, compileUnit);
                int pos = property.Name.IndexOf('.');
                if (pos < 0) {
                    // public string Color { get { return (string) GetProperty("Color"); } set { SetProperty("Color", value); } }
                    CreateCodeForProperty(assemblyBuilder, type, property);
                } else {
                    string grpName = property.Name.Substring(0, pos);
                    if (!assemblyBuilder.CodeDomProvider.IsValidIdentifier(grpName))
                        throw new ConfigurationErrorsException(SR.GetString(SR.Profile_bad_group, grpName), property.FileName, property.LineNumber);
                    if (groups[grpName] == null) {
                        groups.Add(grpName, property.Name);
                    } else {
                        groups[grpName] = ((string)groups[grpName]) + ";" + property.Name;
                    }
                }
            }

            foreach(DictionaryEntry de in groups) {
                // public ProfileGroupFooClass Foo { get { return ProfileGroupSomething; }}
                //
                // public class ProfileGroupFoo : ProfileGroup {
                //      Properties
                // }
                AddPropertyGroup(assemblyBuilder, (string) de.Key, (string) de.Value, properties, type, ns);
            }


            // public ASP.Profile GetProfileForUser(string username) {
            //      return (ASP.Profile) this.GetUserProfile(username);
            // }
            AddCodeForGetProfileForUser(type);

            // }
            //
            ns.Types.Add(type);
            compileUnit.Namespaces.Add(ns);

            assemblyBuilder.AddCodeCompileUnit(this, compileUnit);
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:85,代码来源:ProfileBuildProvider.cs

示例7: GenerateCode

 public override void GenerateCode(AssemblyBuilder assemblyBuilder)
 {
     assemblyBuilder.AddCodeCompileUnit(this, this.GeneratedCode);
     assemblyBuilder.GenerateTypeFactory(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", Compiler.Namespace, Compiler.ClassName));
 }
开发者ID:toptensoftware,项目名称:manos,代码行数:5,代码来源:RazorBuildProvider.cs

示例8: GenerateServiceProxyCode


//.........这里部分代码省略.........
                nameTest.TrueStatements.Add(new CodeMethodReturnStatement(methodInfoRef));
                codeMethod.Statements.Add(nameTest);
            }

            codeMethod.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(null)));
            resourceType.Members.Add(codeMethod);

            #endregion MethodInfo IJrpcServiceInfo.ResolveMethodName(string name);

            #region string[] IJrpcServiceInfo.GetMethodParams(string name);

            codeMethod = new CodeMemberMethod();
            codeMethod.Name = "GetMethodParams";
            codeMethod.PrivateImplementationType = new CodeTypeReference(typeof(IJsonServiceInfo));
            codeMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(String), "name"));
            codeMethod.ReturnType = new CodeTypeReference(typeof(String[]));
            CodeVariableReferenceExpression nameParam2 = new CodeVariableReferenceExpression("name");

            // if (String.IsNullOrEmpty(name)) { return new string[0]; }
            CodeConditionStatement nullCheck2 = new CodeConditionStatement();
            nullCheck2.Condition = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(String)), "IsNullOrEmpty", nameParam);
            nullCheck2.TrueStatements.Add(new CodeMethodReturnStatement(new CodeArrayCreateExpression(typeof(String[]), 0)));
            codeMethod.Statements.Add(nullCheck2);

            foreach (MethodInfo method in methodMap.Values)
            {
                string[] paramMap = JsonServiceBuildProvider.CreateParamMap(method);

                if (paramMap.Length < 1)
                    continue;

                CodeConditionStatement nameTest = new CodeConditionStatement();
                // if (String.Equals(name, method.Name)) { ... }
                nameTest.Condition = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(String)), "Equals", nameParam2, new CodePrimitiveExpression(method.Name));

                // = {...}
                CodePrimitiveExpression[] paramList = new CodePrimitiveExpression[paramMap.Length];
                for (int i=0; i<paramMap.Length; i++)
                {
                    paramList[i] = new CodePrimitiveExpression(paramMap[i]);
                }

                // new string[] = {...}
                CodeArrayCreateExpression paramArray = new CodeArrayCreateExpression(typeof(String[]), paramList);

                // return string[];
                nameTest.TrueStatements.Add(new CodeMethodReturnStatement(paramArray));
                codeMethod.Statements.Add(nameTest);
            }

            codeMethod.Statements.Add(new CodeMethodReturnStatement(new CodeArrayCreateExpression(typeof(String[]), 0)));
            resourceType.Members.Add(codeMethod);

            #endregion string[] IJrpcServiceInfo.GetMethodParams(string name);

            if (this.VirtualPathDependencies.Count > 0)
            {
                resourceType.BaseTypes.Add(typeof(IDependentResult));

                #region private static readonly string[] Dependencies

                field = new CodeMemberField();
                field.Name = "Dependencies";
                field.Type = new CodeTypeReference(typeof(string[]));
                field.Attributes = MemberAttributes.Private|MemberAttributes.Static|MemberAttributes.Final;

                arrayInit = new CodeArrayCreateExpression(field.Type, this.VirtualPathDependencies.Count);
                foreach (string key in this.VirtualPathDependencies)
                {
                    arrayInit.Initializers.Add(new CodePrimitiveExpression(key));
                }
                field.InitExpression = arrayInit;

                resourceType.Members.Add(field);

                #endregion private static readonly string[] Dependencies

                #region IEnumerable<string> IDependentResult.VirtualPathDependencies { get; }

                // add a readonly property returning the static data
                property = new CodeMemberProperty();
                property.Name = "VirtualPathDependencies";
                property.Type = new CodeTypeReference(typeof(IEnumerable<string>));
                property.PrivateImplementationType = new CodeTypeReference(typeof(IDependentResult));
                property.HasGet = true;
                // get { return Dependencies; }
                property.GetStatements.Add(new CodeMethodReturnStatement(
                    new CodeFieldReferenceExpression(
                        new CodeTypeReferenceExpression(resourceType.Name),
                        "Dependencies")));
                resourceType.Members.Add(property);

                #endregion IEnumerable<string> IDependentResult.VirtualPathDependencies { get; }
            }

            // Generate _ASP FastObjectFactory
            assemblyBuilder.GenerateTypeFactory(this.ResourceFullName);

            assemblyBuilder.AddCodeCompileUnit(this, generatedUnit);
        }
开发者ID:pocket-playlab,项目名称:jsonfx-v1,代码行数:101,代码来源:JsonServiceBuildProvider.cs

示例9: GenerateCode


//.........这里部分代码省略.........
            // get { return DeflatedBytes; }
            property.GetStatements.Add(new CodeMethodReturnStatement(
                new CodeFieldReferenceExpression(
                    new CodeTypeReferenceExpression(this.ResourceTypeName),
                    "DeflatedBytes")));
            resourceType.Members.Add(property);

            #endregion byte[] IOptimizedResult.Deflated { get; }

            #region string IBuildResultMeta.ContentType { get; }

            // add a readonly property with the MIME type
            property = new CodeMemberProperty();
            property.Name = "ContentType";
            property.Type = new CodeTypeReference(typeof(String));
            property.PrivateImplementationType = new CodeTypeReference(typeof(IBuildResult));
            property.HasGet = true;
            // get { return contentType; }
            property.GetStatements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(contentType)));
            resourceType.Members.Add(property);

            #endregion string IBuildResultMeta.ContentType { get; }

            #region string IBuildResultMeta.FileExtension { get; }

            // add a readonly property with the MIME type
            property = new CodeMemberProperty();
            property.Name = "FileExtension";
            property.Type = new CodeTypeReference(typeof(String));
            property.PrivateImplementationType = new CodeTypeReference(typeof(IBuildResult));
            property.HasGet = true;
            // get { return fileExtension; }
            property.GetStatements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(fileExtension)));
            resourceType.Members.Add(property);

            #endregion string IBuildResultMeta.FileExtension { get; }

            #region string IBuildResultMeta.Hash { get; }

            // add a readonly property with the resource data
            property = new CodeMemberProperty();
            property.Name = "Hash";
            property.Type = new CodeTypeReference(typeof(String));
            property.PrivateImplementationType = new CodeTypeReference(typeof(IBuildResult));
            property.HasGet = true;
            // get { return hash); }

            property.GetStatements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(hash)));
            resourceType.Members.Add(property);

            #endregion string IBuildResultMeta.Hash { get; }

            if (this.VirtualPathDependencies.Count > 0)
            {
                resourceType.BaseTypes.Add(typeof(IDependentResult));

                #region private static readonly string[] Dependencies

                field = new CodeMemberField();
                field.Name = "Dependencies";
                field.Type = new CodeTypeReference(typeof(string[]));
                field.Attributes = MemberAttributes.Private|MemberAttributes.Static|MemberAttributes.Final;

                arrayInit = new CodeArrayCreateExpression(field.Type, this.VirtualPathDependencies.Count);
                foreach (string key in this.VirtualPathDependencies)
                {
                    arrayInit.Initializers.Add(new CodePrimitiveExpression(key));
                }
                field.InitExpression = arrayInit;

                resourceType.Members.Add(field);

                #endregion private static readonly string[] Dependencies

                #region IEnumerable<string> IDependentResult.VirtualPathDependencies { get; }

                // add a readonly property returning the static data
                property = new CodeMemberProperty();
                property.Name = "VirtualPathDependencies";
                property.Type = new CodeTypeReference(typeof(IEnumerable<string>));
                property.PrivateImplementationType = new CodeTypeReference(typeof(IDependentResult));
                property.HasGet = true;
                // get { return Dependencies; }
                property.GetStatements.Add(new CodeMethodReturnStatement(
                    new CodeFieldReferenceExpression(
                        new CodeTypeReferenceExpression(resourceType.Name),
                        "Dependencies")));
                resourceType.Members.Add(property);

                #endregion IEnumerable<string> IDependentResult.VirtualPathDependencies { get; }
            }

            // allow the code provider to extend with additional properties
            provider.GenerateCodeExtensions(this, resourceType);

            // Generate _ASP FastObjectFactory
            assemblyBuilder.GenerateTypeFactory(this.ResourceFullName);

            assemblyBuilder.AddCodeCompileUnit(this, generatedUnit);
        }
开发者ID:pocket-playlab,项目名称:jsonfx-v1,代码行数:101,代码来源:ResourceBuildProvider.cs

示例10: GenerateCode

 public override void GenerateCode(AssemblyBuilder assemblyBuilder)
 {
     Hashtable propertiesForCompilation = ProfileBase.GetPropertiesForCompilation();
     CodeCompileUnit ccu = new CodeCompileUnit();
     Hashtable hashtable2 = new Hashtable();
     Type type = Type.GetType(ProfileBase.InheritsFromTypeString, false);
     CodeNamespace ns = new CodeNamespace();
     ns.Imports.Add(new CodeNamespaceImport("System"));
     ns.Imports.Add(new CodeNamespaceImport("System.Web"));
     ns.Imports.Add(new CodeNamespaceImport("System.Web.Profile"));
     CodeTypeDeclaration declaration = new CodeTypeDeclaration {
         Name = "ProfileCommon"
     };
     if (type != null)
     {
         declaration.BaseTypes.Add(new CodeTypeReference(type));
         assemblyBuilder.AddAssemblyReference(type.Assembly, ccu);
     }
     else
     {
         declaration.BaseTypes.Add(new CodeTypeReference(ProfileBase.InheritsFromTypeString));
         ProfileSection profileAppConfig = MTConfigUtil.GetProfileAppConfig();
         if (profileAppConfig != null)
         {
             PropertyInformation information = profileAppConfig.ElementInformation.Properties["inherits"];
             if (((information != null) && (information.Source != null)) && (information.LineNumber > 0))
             {
                 declaration.LinePragma = new CodeLinePragma(HttpRuntime.GetSafePath(information.Source), information.LineNumber);
             }
         }
     }
     assemblyBuilder.GenerateTypeFactory("ProfileCommon");
     foreach (DictionaryEntry entry in propertiesForCompilation)
     {
         ProfileNameTypeStruct property = (ProfileNameTypeStruct) entry.Value;
         if (property.PropertyType != null)
         {
             assemblyBuilder.AddAssemblyReference(property.PropertyType.Assembly, ccu);
         }
         int index = property.Name.IndexOf('.');
         if (index < 0)
         {
             this.CreateCodeForProperty(assemblyBuilder, declaration, property);
         }
         else
         {
             string str = property.Name.Substring(0, index);
             if (!assemblyBuilder.CodeDomProvider.IsValidIdentifier(str))
             {
                 throw new ConfigurationErrorsException(System.Web.SR.GetString("Profile_bad_group", new object[] { str }), property.FileName, property.LineNumber);
             }
             if (hashtable2[str] == null)
             {
                 hashtable2.Add(str, property.Name);
             }
             else
             {
                 hashtable2[str] = ((string) hashtable2[str]) + ";" + property.Name;
             }
         }
     }
     foreach (DictionaryEntry entry2 in hashtable2)
     {
         this.AddPropertyGroup(assemblyBuilder, (string) entry2.Key, (string) entry2.Value, propertiesForCompilation, declaration, ns);
     }
     this.AddCodeForGetProfileForUser(declaration);
     ns.Types.Add(declaration);
     ccu.Namespaces.Add(ns);
     assemblyBuilder.AddCodeCompileUnit(this, ccu);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:70,代码来源:ProfileBuildProvider.cs


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