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


C# Emit.ConstructorBuilder类代码示例

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


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

		internal ConstructorEmitter(AbstractTypeEmitter maintype, params ArgumentReference[] arguments)
		{
			this.maintype = maintype;

			var args = ArgumentsUtil.InitializeAndConvert(arguments);

			builder = maintype.TypeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, args);
		}
开发者ID:jeremymeng,项目名称:Core,代码行数:8,代码来源:ConstructorEmitter.cs


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