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


C# ModuleBuilder.GetType方法代码示例

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


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

示例1: DefineUniqueType

 internal static TypeBuilder DefineUniqueType(string strInitFullName, TypeAttributes attrs, Type BaseType, Type[] aInterfaceTypes, ModuleBuilder mb)
 {
     string className = strInitFullName;
     for (int i = 2; mb.GetType(className) != null; i++)
     {
         className = strInitFullName + "_" + i;
     }
     return mb.DefineType(className, attrs, BaseType, aInterfaceTypes);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:9,代码来源:TCEAdapterGenerator.cs

示例2: DefineUniqueType

        internal static TypeBuilder DefineUniqueType(String strInitFullName, TypeAttributes attrs, Type BaseType, Type[] aInterfaceTypes, ModuleBuilder mb)
        {
            String strFullName = strInitFullName;
            int PostFix = 2;

            // Find the first unique name for the type.
            for (; mb.GetType(strFullName) != null; strFullName = strInitFullName + "_" + PostFix, PostFix++);

            // Define a type with the determined unique name.
            return mb.DefineType(strFullName, attrs, BaseType, aInterfaceTypes);
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:11,代码来源:TCEAdapterGenerator.cs

示例3: CreateDelegateType

        public Type CreateDelegateType(MethodInfo method, ModuleBuilder module)
        {
            var name = string.Format("{0}_{1}_Proc", method.Name, string.Join("_", method.GetParameters().Select(p => p.ParameterType.Name)));

            var oldType = module.GetType(name);
            if (oldType != null)
                return oldType;

            var typeBuilder = module.DefineType(
                name, TypeAttributes.Sealed | TypeAttributes.Public, typeof(MulticastDelegate));

            var constructor = typeBuilder.DefineConstructor(
                MethodAttributes.RTSpecialName | MethodAttributes.HideBySig | MethodAttributes.Public,
                CallingConventions.Standard, new[] { typeof(object), typeof(IntPtr) });

            constructor.SetImplementationFlags(MethodImplAttributes.CodeTypeMask);

            var invokeMethod = typeBuilder.DefineMethod(
                "Invoke",
                MethodAttributes.HideBySig | MethodAttributes.Virtual | MethodAttributes.Public,
                method.ReturnType,
                method.GetParameters().Select(p => p.ParameterType).ToArray());

            invokeMethod.SetImplementationFlags(MethodImplAttributes.CodeTypeMask);

            // Copy return type attributes
            if (method.ReturnType != typeof(void))
            {
                ProcessReturnParameterAttributes(method, invokeMethod);
            }

            foreach (var param in method.GetParameters())
            {
                var par = invokeMethod.DefineParameter(param.Position + 1, param.Attributes, param.Name);
                CopyParameterAttributes(par, param);
            }

            return typeBuilder.CreateType();
        }
开发者ID:GeirGrusom,项目名称:PlatformInvoker,代码行数:39,代码来源:DelegateTypeBuilder.cs

示例4: ModuleBuilder_GetType

 // ...
 // There's a bug in ModuleBuilder.GetType(), so we have to use our own 
 // version for now.
 System.Type ModuleBuilder_GetType(ModuleBuilder m, string stType)
 {
 #if false
     // This should work, but is broken for nested types.
     return m.GetType(stType);
 #else        
     // Here's our hack to use in the meantime
     // Note, we have to deal with appended characters like [], and &
     // This is a hack that will work for now. When reflection-emit fixes the 
     // bug, we can get rid of this.
     Type [] al = m.GetTypes();
     foreach(Type t in al)
     {
         if (t.FullName == stType)
             return t;
     }
     return null;    
 #endif
 }
开发者ID:chenzuo,项目名称:blue,代码行数:22,代码来源:EmitCodeGen.cs

示例5: GenerateExe

        public void GenerateExe()
        {
            string AssemblyName = "TestAssembly";
            string ClassName = "TestClass";
            string ExeName = ClassName + ".exe";

            // 获得应用程序域,用于创建程序集。
            domain = Thread.GetDomain();

            // 创建程序集名称。
            name = new AssemblyName();
            name.Name = AssemblyName;

            // 创建程序集。
            asmbuilder = domain.DefineDynamicAssembly(name, AssemblyBuilderAccess.RunAndSave);

            // 创建模块。
            modbuilder = asmbuilder.DefineDynamicModule(ExeName);

            // 创建类型。
            typbuilder = modbuilder.DefineType(ClassName);

            // 创建全局变量(类的静态变量)
            fld = typbuilder.DefineField("haha", typeof(int), FieldAttributes.Static);

            // 创建静态方法Add:public static int Add(int,int)
            addBuilder = typbuilder.DefineMethod("Add", MethodAttributes.Public | MethodAttributes.Static, typeof(int), new Type[] { typeof(int), typeof(int) });

            // 创建静态方法Add:public static int Fact(int)
            factBuilder = typbuilder.DefineMethod("Fact", MethodAttributes.Public | MethodAttributes.Static, typeof(int), new Type[] { typeof(int) });

            // 创建静态方法Main:public static void Main(string[])
            mainBuilder = typbuilder.DefineMethod("Main", MethodAttributes.Public | MethodAttributes.Static, typeof(void), new Type[] { typeof(string[]) });

            // Add方法的代码生成器
            iladd = addBuilder.GetILGenerator();

            // 产生Add方法的代码
            GenerateCodeForAdd();

            // Fact方法的代码生成器
            ilfact = factBuilder.GetILGenerator();

            // 产生Fact方法的代码
            GenerateCodeForFact();

            // Main方法的代码生成器
            ilmain = mainBuilder.GetILGenerator();

            // 产生Main方法的代码。
            GenerateCodeForMain();

            // 类里所有东西都已经定义好了,现在要创建这个类。
            typbuilder.CreateType();

            // 设置入口点。
            asmbuilder.SetEntryPoint((modbuilder.GetType(ClassName)).GetMethod("Main"));

            // 保存到EXE文件。
            asmbuilder.Save(ExeName);
        }
开发者ID:lewischeng-ms,项目名称:misc,代码行数:61,代码来源:codegen.cs


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