• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Emit.ConstructorBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



ConstructorBuilder类属于System.Reflection.Emit命名空间,在下文中一共展示了ConstructorBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DefineDelegate

		/// <summary>
		///   Defines an inner Delegate type for the method to be invoked from Objective-C runtime.
		/// </summary>
		// TODO: Refactor
		private Type DefineDelegate (TypeBuilder typeBuilder, MethodInfo methodInfo, out ConstructorBuilder constructorBuilder)
		{
			// Get info about the target method
			Type returnType = GetReturnType (methodInfo);
			Type nativeReturnType = TypeHelper.GetNativeType (returnType, this.Is64Bits);
			Type[] nativeParameterTypes = TypeHelper.GetNativeParameterTypes (methodInfo, this.Is64Bits);

			// TODO: Refactor
			// Remove first parameter of the extension method
			nativeParameterTypes = ArrayHelper.TrimLeft (nativeParameterTypes, 1);

			// Create the array of parameters for the delegate's invoke method
			nativeParameterTypes = ArrayHelper.Prepend (nativeParameterTypes, typeof(IntPtr), typeof(IntPtr));

			// Assign some names to parameters (for easy debugging)
			String[] parameterNames = TypeHelper.GetParameterNames (methodInfo);

			// TODO: Refactor
			// Remove first parameter of the extension method
			parameterNames = ArrayHelper.TrimLeft (parameterNames, 1);

			String[] nativeParameterNames = new String[nativeParameterTypes.Length];
			Array.Copy (parameterNames, 0, nativeParameterNames, 2, parameterNames.Length);
			nativeParameterNames [0] = "receiver";
			nativeParameterNames [1] = "selector";

			// Create a unique delegate name
			String name = GetUniqueName (methodInfo) + "_Invoker";

			// Create a delegate
			TypeBuilder delegateBuilder = EmitHelper.DefineNestedDelegate (typeBuilder, name, nativeReturnType, nativeParameterTypes, nativeParameterNames, out constructorBuilder);

			// Generate the type
			return delegateBuilder.CreateType ();
		}
开发者ID:Monobjc,项目名称:monobjc,代码行数:39,代码来源:CategoryGenerator.Generation.cs


示例2: ILConstructorDebugImpl

 public ILConstructorDebugImpl(ConstructorBuilder constructor, IILGenForbidenInstructions forbidenInstructions, SourceCodeWriter sourceCodeWriter)
 {
     _constructor = constructor;
     _sourceCodeWriter = sourceCodeWriter;
     _forbidenInstructions = forbidenInstructions;
     _expectedLength = 64;
 }
开发者ID:mano-cz,项目名称:BTDB,代码行数:7,代码来源:ILConstructorDebugImpl.cs


示例3: Compile

 internal void Compile(ConstructorBuilder c)
 {
     if (Builder == null)
     {
         int ofs = (c.IsStatic ? 0 : 1);
         Builder = c.DefineParameter(this.Index + ofs, this.Attributes, this.Name);
     }
 }
开发者ID:rreynolds-yp,项目名称:csharp-swift-consoleclient,代码行数:8,代码来源:EmittedParameter.cs


示例4: ConstructorBuilderHelper

		/// <summary>
		/// Initializes a new instance of the <see cref="ConstructorBuilder"/> class
		/// with the specified parameters.
		/// </summary>
		/// <param name="typeBuilder">Associated <see cref="TypeBuilderHelper"/>.</param>
		/// <param name="constructorBuilder">A <see cref="ConstructorBuilder"/></param>
		public ConstructorBuilderHelper(TypeBuilderHelper typeBuilder, ConstructorBuilder constructorBuilder)
			: base(typeBuilder)
		{
			if (constructorBuilder == null) throw new ArgumentNullException("constructorBuilder");

			_constructorBuilder = constructorBuilder;
			_constructorBuilder.SetCustomAttribute(Type.Assembly.BLToolkitAttribute);
		}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:14,代码来源:ConstructorBuilderHelper.cs


示例5: DefineParams

 public static void DefineParams(ConstructorBuilder constructorBuilder, IEnumerable<RppParameterInfo> constructorParams)
 {
     int index = 1;
     foreach (var param in constructorParams)
     {
         constructorBuilder.DefineParameter(index++, ParameterAttributes.None, RppClass.StringConstructorArgName(param.Name));
     }
 }
开发者ID:dubik,项目名称:csharprpp,代码行数:8,代码来源:RTypeUtils.cs


示例6: EnhanceType

        private void EnhanceType(TypeBuilder mainType, FieldBuilder handlerFieldBuilder, ConstructorBuilder constructorBuilder)
        {
            Assert.IsTrue( !m_enhanceInvoked );

            Assert.IsNotNull(mainType);
            Assert.IsNotNull(handlerFieldBuilder);
            Assert.IsNotNull(constructorBuilder);

            m_enhanceInvoked = true;
        }
开发者ID:BackupTheBerlios,项目名称:dpml-svn,代码行数:10,代码来源:CustomProxyGeneratorTestCase.cs


示例7: DefineLoaderType

 protected void DefineLoaderType(ConstructorBuilder factoryConstructorBuilder)
 {
     loaderBuilder.AddInterfaceImplementation(typeof(IFactoryLoader));
     loaderBuilder.DefineDefaultConstructor(MethodAttributes.Public);
     var methodIl = loaderBuilder.DefineMethod("CreateFactory", MethodAttributes.Public | MethodAttributes.Virtual,
         typeof(object), factoryContructorParameters).GetILGenerator();
     methodIl.Emit(OpCodes.Ldarg_1);
     methodIl.Emit(OpCodes.Newobj, factoryConstructorBuilder);
     methodIl.Emit(OpCodes.Ret);
 }
开发者ID:nmuhonen,项目名称:Inferables-For-CLR,代码行数:10,代码来源:FactoryGenerator.cs


示例8: EmitConstrucorIL

        public void EmitConstrucorIL(ConstructorBuilder builder)
        {
            ConstructorInfo conObj = typeof(object).GetConstructor(new Type[0]);

            //call constructor of base object
            ILGenerator il = builder.GetILGenerator();
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Call, conObj);
            il.Emit(OpCodes.Ret);
        }
开发者ID:dotnetprogrammr,项目名称:TypeFactory,代码行数:10,代码来源:ILManager.cs


示例9: DefineParameterNames

        private static void DefineParameterNames(
            ConstructorBuilder constructor, 
            ConstructorMetadata constructorMetadata)
        {
            for (var i = 0; i < constructorMetadata.Parameters.Length; i++)
            {
                var parameter = constructorMetadata.Parameters[i];

                constructor.DefineParameter(parameter.Sequence, ParameterAttributes.None, parameter.Name);
            }
        }
开发者ID:bradleyjford,项目名称:inception,代码行数:11,代码来源:ConstructorGenerator.cs


示例10: EmitCtor

	static void EmitCtor (TypeBuilder genericFoo) {
		ConstructorBuilder mb = genericFoo.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, null);
		ILGenerator il = mb.GetILGenerator ();
		for (int i = 0; i < 20; ++i)
				il.Emit (OpCodes.Nop);

		il.Emit (OpCodes.Ldarg_0);
		il.Emit (OpCodes.Call, typeof (object).GetConstructors()[0]);
		il.Emit (OpCodes.Ret);

		ctor = mb;
	}
开发者ID:Zman0169,项目名称:mono,代码行数:12,代码来源:bug-389886-2.cs


示例11: DefineConstructorBuilder

        public ConstructorBuilder DefineConstructorBuilder()
        {
            if (IsConstructor)
            {
                ConstructorBuilder = Parent.TypeBuilder.DefineConstructor(
                    GetMethodModifiers(),
                    CallingConventions.Standard,
                    GetArgumentTypes());
            }
            else
            {
                ConstructorBuilder = Parent.TypeBuilder.DefineTypeInitializer();
            }

            return ConstructorBuilder;
        }
开发者ID:robertsundstrom,项目名称:vb-lite-compiler,代码行数:16,代码来源:ConstructorDef.cs


示例12: GetInitConstructorIL

 protected ILGenerator GetInitConstructorIL(ConstructorBuilder constructorBuilder, Dictionary<TypeFactoryMap, FieldBuilder> singletonFields)
 {
     var constrIl = constructorBuilder.GetILGenerator();
     constrIl.Emit(OpCodes.Ldarg_0);
     constrIl.Emit(OpCodes.Call, typeof(object).GetConstructor(Type.EmptyTypes));
     foreach (var fieldPair in singletonFields)
     {
         var injectableGetSingletonMethod = typeof(IInjectableModule).GetMethod("GetSingleton").MakeGenericMethod(fieldPair.Key.BaseType);
         constrIl.Emit(OpCodes.Ldarg_0);
         constrIl.Emit(OpCodes.Ldarg_1);
         constrIl.Emit(OpCodes.Ldstr, fieldPair.Key.Name);
         constrIl.Emit(OpCodes.Callvirt, injectableGetSingletonMethod);
         constrIl.Emit(OpCodes.Stfld, fieldPair.Value);
     }
     return constrIl;
 }
开发者ID:nmuhonen,项目名称:Inferables-For-CLR,代码行数:16,代码来源:FactoryGenerator.cs


示例13: PrepareSelf

        /// <summary>
        /// Creates a ConstructorBuilder for current constructor entity.
        /// </summary>
        public override void PrepareSelf()
        {
            // todo: remove when we support static ctors
            if(IsStatic)
                throw new LensCompilerException(CompilerMessages.ConstructorStatic);

            if (ConstructorBuilder != null || IsImported)
                return;

            var ctx = ContainerType.Context;

            if (ArgumentTypes == null)
                ArgumentTypes = Arguments == null
                    ? new Type[0]
                    : Arguments.Values.Select(fa => fa.GetArgumentType(ctx)).ToArray();

            ConstructorBuilder = ContainerType.TypeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, ArgumentTypes);
            Generator = ConstructorBuilder.GetILGenerator(Context.ILStreamSize);
        }
开发者ID:TrickyCat,项目名称:lens,代码行数:22,代码来源:ConstructorEntity.cs


示例14: EmitCtor

 private void EmitCtor(PropertyAndField[] properties, ConstructorBuilder method)
 {
     ILGenerator iLGenerator = method.GetILGenerator();
     iLGenerator.Emit(OpCodes.Ldarg_0);
     iLGenerator.Emit(OpCodes.Call, ObjectType.GetConstructor(Type.EmptyTypes));
     int index = 0;
     if (0 < properties.Length)
     {
         do
         {
             iLGenerator.Emit(OpCodes.Ldarg_0);
             int arg = index + 1;
             iLGenerator.Emit(OpCodes.Ldarg, arg);
             iLGenerator.Emit(OpCodes.Stfld, properties[index].Field);
             index = arg;
         }
         while (index < properties.Length);
     }
     iLGenerator.Emit(OpCodes.Ret);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:20,代码来源:AnonymousTypeEmitter.cs


示例15: ILEmitter

		/// <summary>
		/// Creates a new <see cref="ILEmitter"/> for a given <see cref="ConstructorBuilder"/>.
		/// </summary>
		/// <param name="constructorBuilder">The <see cref="ConstructorBuilder"/> to emit to.</param>
		public ILEmitter(ConstructorBuilder/*!*/ constructorBuilder)
			: this(constructorBuilder.GetILGenerator(), Containers.ConstructorBuilder)
		{
			this.method = constructorBuilder;
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:9,代码来源:ILEmitter.cs


示例16: GenerateStaticGetList

        private void GenerateStaticGetList(TypeBuilder t, ConstructorBuilder ctor)
        {
            Type tt = ctor.DeclaringType.MakeArrayType();

            MethodInfo mi = typeof(DalUtility).GetMethod("GetList",
                BindingFlags.Static |
                BindingFlags.Public);
            MethodInfo genericMi = mi.MakeGenericMethod(new Type[] { ctor.DeclaringType });

            MethodBuilder mb = t.DefineMethod("GetList",
                MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig,
                tt, Type.EmptyTypes);
            ILGenerator gen = mb.GetILGenerator();
            gen.DeclareLocal(tt);
            Label l1 = gen.DefineLabel();
            gen.Emit(OpCodes.Nop);
            gen.Emit(OpCodes.Call, genericMi);
            gen.Emit(OpCodes.Stloc_0);
            gen.Emit(OpCodes.Br_S, l1);
            gen.MarkLabel(l1);
            gen.Emit(OpCodes.Ldloc_0);
            gen.Emit(OpCodes.Ret);
        }
开发者ID:paveltimofeev,项目名称:MSIL-DAL-Generator,代码行数:23,代码来源:DFacto.cs


示例17: GenerateStaticGet

        private void GenerateStaticGet(TypeBuilder t, ConstructorBuilder ctor)
        {
            MethodBuilder mb = t.DefineMethod("Get",
                MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig,
                ctor.DeclaringType, new Type[] { typeof(Int32) });

            ILGenerator gen = mb.GetILGenerator();
            Label l1 = gen.DefineLabel();
            gen.DeclareLocal(ctor.DeclaringType);
            gen.Emit(OpCodes.Nop);
            gen.Emit(OpCodes.Ldarg_0);
            gen.Emit(OpCodes.Newobj, ctor);
            gen.Emit(OpCodes.Stloc_0);
            gen.Emit(OpCodes.Br_S, l1);
            gen.MarkLabel(l1);
            gen.Emit(OpCodes.Ldloc_0);
            gen.Emit(OpCodes.Ret);
        }
开发者ID:paveltimofeev,项目名称:MSIL-DAL-Generator,代码行数:18,代码来源:DFacto.cs


示例18: DefineConstructorNoLock

        [System.Security.SecurityCritical]  // auto-generated
        private ConstructorBuilder DefineConstructorNoLock(MethodAttributes attributes, CallingConventions callingConvention, 
            Type[] parameterTypes, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers)
        {
            CheckContext(parameterTypes);
            CheckContext(requiredCustomModifiers);
            CheckContext(optionalCustomModifiers);

            ThrowIfCreated();

            String name;

            if ((attributes & MethodAttributes.Static) == 0)
            {
                name = ConstructorInfo.ConstructorName;
            }
            else
            {
                name = ConstructorInfo.TypeConstructorName;
            }

            attributes = attributes | MethodAttributes.SpecialName;

            ConstructorBuilder constBuilder = 
                new ConstructorBuilder(name, attributes, callingConvention, 
                    parameterTypes, requiredCustomModifiers, optionalCustomModifiers, m_module, this);

            m_constructorCount++;

            return constBuilder;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:31,代码来源:typebuilder.cs


示例19: DefineTypeInitializerNoLock

        [System.Security.SecurityCritical]  // auto-generated
        private ConstructorBuilder DefineTypeInitializerNoLock()
        {
            ThrowIfCreated();

            // change the attributes and the class constructor's name
            MethodAttributes attr = MethodAttributes.Private | MethodAttributes.Static | MethodAttributes.SpecialName;

            ConstructorBuilder constBuilder = new ConstructorBuilder(
                ConstructorInfo.TypeConstructorName, attr, CallingConventions.Standard, null, m_module, this);

            return constBuilder;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:13,代码来源:typebuilder.cs


示例20: DefineConstructor

		public ConstructorBuilder DefineConstructor (MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers)
		{
			check_not_created ();
			ConstructorBuilder cb = new ConstructorBuilder (this, attributes,
				callingConvention, parameterTypes, requiredCustomModifiers,
				optionalCustomModifiers);
			if (ctors != null) {
				ConstructorBuilder[] new_ctors = new ConstructorBuilder [ctors.Length+1];
				System.Array.Copy (ctors, new_ctors, ctors.Length);
				new_ctors [ctors.Length] = cb;
				ctors = new_ctors;
			} else {
				ctors = new ConstructorBuilder [1];
				ctors [0] = cb;
			}
			return cb;
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:17,代码来源:TypeBuilder.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Emit.CustomAttributeBuilder类代码示例发布时间:2022-05-26
下一篇:
C# Emit.CodeGenerator类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap