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


C# TypeBuilder.DefineConstructor方法代码示例

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


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

示例1: ClassBuilder

        public ClassBuilder(TypeBuilder tb)
        {
            this.tb = tb;
            System.Type[] param = {};

            ConstructorBuilder ctor = tb.DefineConstructor( MethodAttributes.Public, CallingConventions.Standard, param );
            cil = ctor.GetILGenerator();

            ctor = tb.DefineConstructor(MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, param);
            ccil = ctor.GetILGenerator();
        }
开发者ID:bi-tm,项目名称:openABAP,代码行数:11,代码来源:ClassBuilder.cs

示例2: BuildConstructor

        private static void BuildConstructor(TypeBuilder proxyBuilder, Type proxyType,
			 FieldBuilder wrappedType, FieldBuilder invokeHandlers, TypeDebugging debug)
        {
            var arguments = new Type[] { proxyType, typeof(IInvocationHandler[]) };
            var constructor = proxyBuilder.DefineConstructor(
                MethodAttributes.Public | MethodAttributes.SpecialName |
                MethodAttributes.RTSpecialName | MethodAttributes.HideBySig,
                CallingConventions.Standard, arguments);

            using (var generator = debug.GetMethodDebugging(constructor))
            {
                //  Call the base constructor.
                generator.Emit(OpCodes.Ldarg_0);
                var objectCtor = proxyType.GetConstructor(Type.EmptyTypes);
                generator.Emit(OpCodes.Call, objectCtor);
                //  Store the target object.
                generator.Emit(OpCodes.Ldarg_0);
                generator.Emit(OpCodes.Ldarg_1);
                generator.Emit(OpCodes.Stfld, wrappedType);
                //  Store the handlers.
                generator.Emit(OpCodes.Ldarg_0);
                generator.Emit(OpCodes.Ldarg_2);
                generator.Emit(OpCodes.Stfld, invokeHandlers);
                generator.Emit(OpCodes.Ret);
            }
        }
开发者ID:JasonBock,项目名称:DynamicProxies,代码行数:26,代码来源:ProxyConstructorBuilder.cs

示例3: GrabConstructor

 protected ConstructorInfo GrabConstructor(ConstructorInfo Original, TypeBuilder On)
 {
     if(Original == null) return null;
     
     if(ConstructorsDone.ContainsKey(Original))
         return ConstructorsDone[Original];
     
     if(!Sources.Contains(Original.Module))
         return ConstructorReplaceGenerics(Original);
     
     if(On == null)
         On = GrabType(Original.DeclaringType) as TypeBuilder;
     
     ConstructorBuilder Builder = On.DefineConstructor(Original.Attributes, 
         Original.CallingConvention, ParameterTypes(Original));
     
     Builder.SetImplementationFlags(Original.GetMethodImplementationFlags());
     
     if(ConstructorsDone.ContainsKey(Original))
         return ConstructorsDone[Original];
     
     ConstructorsDone.Add(Original, Builder);
     
     CopyMethodBody(Original, Builder);
     
     return Builder;
 }
开发者ID:BillTheBest,项目名称:IronAHK,代码行数:27,代码来源:GrabConstructor.cs

示例4: CreateConstructor

        private static void CreateConstructor(TypeBuilder tb, IList<IInjectableConstructorArg> properties)
        {
            var constructor = tb.DefineConstructor(
                MethodAttributes.Public |
                MethodAttributes.SpecialName |
                MethodAttributes.RTSpecialName,
                CallingConventions.Standard,
                properties.Select(p => p.PropertyType).ToArray());

            var conObj = typeof(object).GetConstructor(new Type[0]);

            ILGenerator il = constructor.GetILGenerator();
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Call, conObj);
            il.Emit(OpCodes.Nop);
            il.Emit(OpCodes.Nop);

            for (var i = 0; i < properties.Count; i++)
            {
                var property = properties[i];

                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Ldarg, i + 1);
                il.Emit(OpCodes.Call, property.Setter);
                il.Emit(OpCodes.Nop);
            }

            il.Emit(OpCodes.Nop);
            il.Emit(OpCodes.Ret);
        }
开发者ID:DivineInject,项目名称:DivineInject,代码行数:30,代码来源:FactoryClass.cs

示例5: Emit

        /// <summary>
        /// Uses reflection to emit the given <see cref="ConstructorInfo"/> body for the given type.
        /// </summary>
        /// <param name="typeBuilder">
        /// The <see cref="TypeBuilder"/>.
        /// </param>
        /// <param name="constructorInfo">
        /// The <see cref="ConstructorInfo"/>.
        /// </param>
        public static void Emit(TypeBuilder typeBuilder, ConstructorInfo constructorInfo)
        {
            // Define the default constructor attributes.
            const MethodAttributes ConstructorAttributes = MethodAttributes.Public |
                                                           MethodAttributes.HideBySig |
                                                           MethodAttributes.SpecialName |
                                                           MethodAttributes.RTSpecialName;

            // Get the parameters.
            Type[] parameterTypes = constructorInfo.GetParameters().Select(p => p.ParameterType).ToArray();

            // Define the constructor.
            ConstructorBuilder constructor = typeBuilder.DefineConstructor(
                                                            ConstructorAttributes,
                                                            CallingConventions.Standard,
                                                            parameterTypes);

            ILGenerator il = constructor.GetILGenerator();

            // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
            constructor.SetImplementationFlags(MethodImplAttributes.IL | MethodImplAttributes.Managed);

            // Load all constructor arguments. Note argument 0 is 'this' pointer, so you must emit one more.
            for (int i = 0; i <= parameterTypes.Length; i++)
            {
                il.Emit(OpCodes.Ldarg_S, i);
            }

            // Call the base constructor and return.
            il.Emit(OpCodes.Call, constructorInfo);
            il.Emit(OpCodes.Ret);
        }
开发者ID:robertjf,项目名称:umbraco-ditto,代码行数:41,代码来源:ConstructorEmitter.cs

示例6: DefineConstructor

 /// <summary>
 /// Defines the constructor used.
 /// </summary>
 /// <param name="owner"></param>
 /// <param name="interfaceType"></param>
 /// <returns></returns>
 protected override ConstructorBuilder DefineConstructor(TypeBuilder owner, Type interfaceType)
 {
     var probeType = typeof(IMethodCallProbe<>).MakeGenericType(interfaceType);
     return owner.DefineConstructor(
         MethodAttributes.Public,
         CallingConventions.Standard,
         new[] { typeof(ILibrary), probeType });
 }
开发者ID:GeirGrusom,项目名称:PlatformInvoker,代码行数:14,代码来源:ProbingConstructorBuilder.cs

示例7: BFMemory

        public BFMemory(TypeBuilder typeBuilder)
        {
            PointerFieldBuilder = typeBuilder.DefineField("pointer", typeof(short), FieldAttributes.Static | FieldAttributes.Private);
            MemoryFieldBuilder = typeBuilder.DefineField("memory", typeof(byte[]), FieldAttributes.Static | FieldAttributes.Private);

            var staticConstructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Static,CallingConventions.Standard, null);
            GenerateStaticConstructorBody(staticConstructorBuilder.GetILGenerator());
        }
开发者ID:brunotag,项目名称:bfcompiler,代码行数:8,代码来源:BFMemory.cs

示例8: GenerateConstructor

 public ConstructorBuilder GenerateConstructor(TypeBuilder builder, Type[] parameters)
 {
     return builder.DefineConstructor(
         MethodAttributes.Public |
         MethodAttributes.SpecialName |
         MethodAttributes.RTSpecialName,
         CallingConventions.Standard,
         parameters);
 }
开发者ID:dotnetprogrammr,项目名称:TypeFactory,代码行数:9,代码来源:ConstructorManager.cs

示例9: CodeMethod

		CodeMethod (CodeClass cls, MethodAttributes attributes, Type[] parameterTypes) 
		{
			this.cls = cls;
			this.typeBuilder = cls.TypeBuilder;
			this.attributes = attributes;
			this.parameterTypes = parameterTypes;
			this.name = typeBuilder.Name;
		
			methodBase = typeBuilder.DefineConstructor (attributes, CallingConventions.Standard, parameterTypes);
			builder = new CodeBuilder (cls);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:11,代码来源:CodeMethod.cs

示例10: BuildConstructor

 private static ConstructorInfo BuildConstructor(TypeBuilder type, FieldInfo helperClassFieldInfo)
 {
     // Declaring method builder
     // Method attributes
     ConstructorBuilder method = type.DefineConstructor(MethodAttributes.Public, 0, new[] { typeof(IDbConnection) });
     // Preparing Reflection instances
     ConstructorInfo ctor1 = typeof(DebuggerNonUserCodeAttribute).GetConstructor(
         BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
         null,
         new Type[]{
     },
         null
         );
     ConstructorInfo ctor2 = typeof(DataContextBase).GetConstructor(
         BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
         null,
         new Type[]{
     typeof(IDbConnection)
     },
         null
         );
     ConstructorInfo ctor3 = typeof(SqlDataContextHelperClass).GetConstructor(
         BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
         null,
         new Type[]{
     typeof(DataContext)
     },
         null
         );
     FieldInfo field4 = helperClassFieldInfo;
     // Adding custom attributes to method
     // [DebuggerNonUserCodeAttribute]
     method.SetCustomAttribute(
         new CustomAttributeBuilder(
             ctor1,
             new Type[] { }
             )
         );
     // Parameter connection
     //ParameterBuilder connection = method.DefineParameter(0, ParameterAttributes.None, "connection");
     ILGenerator gen = method.GetILGenerator();
     // Writing body
     gen.Emit(OpCodes.Ldarg_0);
     gen.Emit(OpCodes.Ldarg_1);
     gen.Emit(OpCodes.Call, ctor2);
     gen.Emit(OpCodes.Ldarg_0);
     gen.Emit(OpCodes.Ldarg_0);
     gen.Emit(OpCodes.Newobj, ctor3);
     gen.Emit(OpCodes.Stfld, field4);
     gen.Emit(OpCodes.Ret);
     // finished
     return method;
 }
开发者ID:DBailey635,项目名称:C1-CMS,代码行数:53,代码来源:DataContextAssembler.cs

示例11: Constructor

 private void Constructor(TypeBuilder typeBuilder)
 {
     var constructor = typeBuilder.DefineConstructor(MethodAttributes.Public | MethodAttributes.RTSpecialName, CallingConventions.Standard, new[] { typeof(IDynamicImplementation) });
     var constructorILGenerator = constructor.GetILGenerator();
     constructorILGenerator.Emit(OpCodes.Ldarg_0);
     var originalConstructor = typeof(Object).GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new Type[0], null);
     constructorILGenerator.Emit(OpCodes.Call, originalConstructor);
     constructorILGenerator.Emit(OpCodes.Ldarg_0);
     constructorILGenerator.Emit(OpCodes.Ldarg_1);
     constructorILGenerator.Emit(OpCodes.Stfld, __interceptionService);
     constructorILGenerator.Emit(OpCodes.Ret);
 }
开发者ID:PaulStovell,项目名称:bindable,代码行数:12,代码来源:DelegatingTypeGenerator.cs

示例12: WeaveConstructor

        private void WeaveConstructor(TypeBuilder typeBuilder, EventBrokerResolvedType eventBrokerResolvedType)
        {
            ConstructorBuilder ctor = null;
            ILGenerator ilGenerator = null;
            var ctorArgs = new[] { eventBrokerResolvedType.DecalringType, typeof(EventInfo), eventBrokerResolvedType.EventBrokerInvokeDelegateType };
            var baseCtor = eventBrokerResolvedType.EventBrokerBaseClassType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, Type.DefaultBinder, ctorArgs, null);

            ctor = typeBuilder.DefineConstructor(ctorAttrs, CallingConventions.Standard | CallingConventions.HasThis, ctorArgs);
            ilGenerator = ctor.GetILGenerator();
            ilGenerator.EmitLoadArg(0);
            ctorArgs.ForEach(1, (arg, i) => ilGenerator.EmitLoadArg(i));
            ilGenerator.Emit(OpCodes.Call, baseCtor);
            ilGenerator.Emit(OpCodes.Ret);
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:14,代码来源:EventBrokerWeaver.cs

示例13: GenerateConstructor

        private static void GenerateConstructor(TypeBuilder typeBuilder)
        {
            var constructor = typeBuilder.DefineConstructor(
                 MethodAttributes.Public | MethodAttributes.SpecialName |
                 MethodAttributes.RTSpecialName,
                 CallingConventions.Standard, Type.EmptyTypes);

            var constructorMethod = typeof(object).GetConstructor(Type.EmptyTypes);
            var constructorGenerator = constructor.GetILGenerator();

            constructorGenerator.Emit(OpCodes.Ldarg_0);
            constructorGenerator.Emit(OpCodes.Call, constructorMethod);
            constructorGenerator.Emit(OpCodes.Ret);
        }
开发者ID:JasonBock,项目名称:DynamicProxies,代码行数:14,代码来源:AssemblyGenerator.cs

示例14: Build

        public void Build(TypeBuilder typeBuilder, Type contractType)
        {
            ConstructorBuilder constructor = typeBuilder.DefineConstructor(
                MethodAttributes.Public, CallingConventions.HasThis, new[] { contractType, typeof(IPointcut[]) });

            ILGenerator il = constructor.GetILGenerator();

            // call base constructor passing second parameter of this constructor as argument
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldarg_1);
            il.Emit(OpCodes.Ldarg_2);
            il.Emit(OpCodes.Call, typeof(InvocationProxy).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).First());

            il.Emit(OpCodes.Ret);
        }
开发者ID:fkalseth,项目名称:tinyaop,代码行数:15,代码来源:ProxyConstructorImplementationStrategy.cs

示例15: DefineForwardingConstructor

 private static void DefineForwardingConstructor(TypeBuilder definingType, Type baseType, Type[] parameters, Type[] baseParams, string[] paramNames, Action<ILGenerator> paramIL)
 {
     ConstructorBuilder builder = definingType.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, parameters);
     int num = 0;
     foreach (string str in paramNames)
     {
         builder.DefineParameter(++num, ParameterAttributes.None, str);
     }
     ILGenerator iLGenerator = builder.GetILGenerator();
     iLGenerator.Emit(OpCodes.Ldarg_0);
     paramIL(iLGenerator);
     ConstructorInfo constructor = baseType.GetConstructor(baseParams);
     iLGenerator.Emit(OpCodes.Call, constructor);
     iLGenerator.Emit(OpCodes.Ret);
 }
开发者ID:CuneytKukrer,项目名称:TestProject,代码行数:15,代码来源:EmissionsGenerator.cs


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