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

C# Emit.TypeBuilder类代码示例

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

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



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

示例1: CreateProxiedMethod

		public void CreateProxiedMethod(FieldInfo field, MethodInfo method, TypeBuilder typeBuilder)
		{
			const MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig |
																								MethodAttributes.Virtual;
			ParameterInfo[] parameters = method.GetParameters();

			MethodBuilder methodBuilder = typeBuilder.DefineMethod(method.Name, methodAttributes,
			                                                       CallingConventions.HasThis, method.ReturnType,
			                                                       parameters.Select(param => param.ParameterType).ToArray());

			System.Type[] typeArgs = method.GetGenericArguments();

			if (typeArgs.Length > 0)
			{
				var typeNames = new List<string>();

				for (int index = 0; index < typeArgs.Length; index++)
				{
					typeNames.Add(string.Format("T{0}", index));
				}

				methodBuilder.DefineGenericParameters(typeNames.ToArray());
			}

			ILGenerator IL = methodBuilder.GetILGenerator();

			Debug.Assert(MethodBodyEmitter != null);
			MethodBodyEmitter.EmitMethodBody(IL, method, field);
		}
开发者ID:pontillo,项目名称:PowerNap,代码行数:29,代码来源:DefaultProxyMethodBuilder.cs


示例2: ImplementProxy

		public void ImplementProxy(TypeBuilder typeBuilder)
		{
			// Implement the IProxy interface
			typeBuilder.AddInterfaceImplementation(typeof (IProxy));

			field = typeBuilder.DefineField("__interceptor", typeof (IInterceptor), FieldAttributes.Private);

			// Implement the getter
			MethodBuilder getterMethod = typeBuilder.DefineMethod("get_Interceptor", InterceptorMethodsAttributes, CallingConventions.HasThis, typeof(IInterceptor), new System.Type[0]);
			getterMethod.SetImplementationFlags(MethodImplAttributes.Managed | MethodImplAttributes.IL);

			ILGenerator IL = getterMethod.GetILGenerator();

			// This is equivalent to:
			// get { return __interceptor;
			IL.Emit(OpCodes.Ldarg_0);
			IL.Emit(OpCodes.Ldfld, field);
			IL.Emit(OpCodes.Ret);

			// Implement the setter
			MethodBuilder setterMethod = typeBuilder.DefineMethod("set_Interceptor", InterceptorMethodsAttributes, CallingConventions.HasThis, typeof (void), new[] {typeof (IInterceptor)});

			setterMethod.SetImplementationFlags(MethodImplAttributes.Managed | MethodImplAttributes.IL);
			IL = setterMethod.GetILGenerator();
			IL.Emit(OpCodes.Ldarg_0);
			IL.Emit(OpCodes.Ldarg_1);
			IL.Emit(OpCodes.Stfld, field);
			IL.Emit(OpCodes.Ret);

			MethodInfo originalSetter = typeof (IProxy).GetMethod("set_Interceptor");
			MethodInfo originalGetter = typeof (IProxy).GetMethod("get_Interceptor");

			typeBuilder.DefineMethodOverride(setterMethod, originalSetter);
			typeBuilder.DefineMethodOverride(getterMethod, originalGetter);
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:35,代码来源:ProxyImplementor.cs


示例3: EventBuilder

#pragma warning restore 169, 414

		internal EventBuilder (TypeBuilder tb, string eventName, EventAttributes eventAttrs, Type eventType) {
			name = eventName;
			attrs = eventAttrs;
			type = eventType;
			typeb = tb;
			table_idx = get_next_table_index (this, 0x14, true);
		}
开发者ID:carrie901,项目名称:mono,代码行数:9,代码来源:EventBuilder.cs


示例4: MethodBuilder

#pragma warning restore 169, 414

		internal MethodBuilder (TypeBuilder tb, string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnModReq, Type[] returnModOpt, Type[] parameterTypes, Type[][] paramModReq, Type[][] paramModOpt)
		{
			this.name = name;
			this.attrs = attributes;
			this.call_conv = callingConvention;
			this.rtype = returnType;
			this.returnModReq = returnModReq;
			this.returnModOpt = returnModOpt;
			this.paramModReq = paramModReq;
			this.paramModOpt = paramModOpt;
			// The MSDN docs does not specify this, but the MS MethodBuilder
			// appends a HasThis flag if the method is not static
			if ((attributes & MethodAttributes.Static) == 0)
 				this.call_conv |= CallingConventions.HasThis;
			if (parameterTypes != null) {
				for (int i = 0; i < parameterTypes.Length; ++i)
					if (parameterTypes [i] == null)
						throw new ArgumentException ("Elements of the parameterTypes array cannot be null", "parameterTypes");

				this.parameters = new Type [parameterTypes.Length];
				System.Array.Copy (parameterTypes, this.parameters, parameterTypes.Length);
			}
			type = tb;
			table_idx = get_next_table_index (this, 0x06, true);

			((ModuleBuilder)tb.Module).RegisterToken (this, GetToken ().Token);
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:29,代码来源:MethodBuilder.cs


示例5: PropertyEmitter

		public PropertyEmitter(TypeBuilder owner, string name, Type propertyType, FieldBuilder propertyChangedField) {
			this.owner = owner;
			this.propertyChangedField = propertyChangedField;
			fieldBuilder = owner.DefineField(String.Format("<{0}>", name), propertyType, FieldAttributes.Private);
			getterBuilder = owner.DefineMethod(String.Format("get_{0}", name), MethodAttributes.Public|MethodAttributes.Virtual|MethodAttributes.HideBySig|MethodAttributes.SpecialName, propertyType, Type.EmptyTypes);
			ILGenerator getterIl = getterBuilder.GetILGenerator();
			getterIl.Emit(OpCodes.Ldarg_0);
			getterIl.Emit(OpCodes.Ldfld, fieldBuilder);
			getterIl.Emit(OpCodes.Ret);
			setterBuilder = owner.DefineMethod(String.Format("set_{0}", name), MethodAttributes.Public|MethodAttributes.Virtual|MethodAttributes.HideBySig|MethodAttributes.SpecialName, typeof(void), new[] {propertyType});
			ILGenerator setterIl = setterBuilder.GetILGenerator();
			setterIl.Emit(OpCodes.Ldarg_0);
			setterIl.Emit(OpCodes.Ldarg_1);
			setterIl.Emit(OpCodes.Stfld, fieldBuilder);
			if (propertyChangedField != null) {
				setterIl.Emit(OpCodes.Ldarg_0);
				setterIl.Emit(OpCodes.Dup);
				setterIl.Emit(OpCodes.Ldfld, propertyChangedField);
				setterIl.Emit(OpCodes.Ldstr, name);
				setterIl.Emit(OpCodes.Call, proxyBase_NotifyPropertyChanged);
			}
			setterIl.Emit(OpCodes.Ret);
			propertyBuilder = owner.DefineProperty(name, PropertyAttributes.None, propertyType, null);
			propertyBuilder.SetGetMethod(getterBuilder);
			propertyBuilder.SetSetMethod(setterBuilder);
		}
开发者ID:NicoGBN,项目名称:AutoMapper,代码行数:26,代码来源:PropertyEmitter.cs


示例6: GenerateInvocation

        /// <summary>
        /// Creates a <see cref="MethodBuilder"/> and implements a default wrapper.
        /// </summary>
        /// <param name="owner">The type that will own this method.</param>
        /// <param name="interfaceType">Type of interface implemented by the <paramref name="owner"/>.</param>
        /// <param name="overrideMethod">Method to override.</param>
        /// <param name="fieldBuilders">Fields specified by the <see paramref="owner"/>.</param>
        /// <returns>MethodBuilder with an already implemented wrapper.</returns>
        public MethodBuilder GenerateInvocation(TypeBuilder owner, Type interfaceType, MethodInfo overrideMethod, IEnumerable<FieldBuilder> fieldBuilders)
        {
            var result = owner.DefineMethod
                    (
                        overrideMethod.Name,
                        MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final |
                        MethodAttributes.HideBySig | MethodAttributes.NewSlot,
                        overrideMethod.ReturnType,
                        overrideMethod.GetParameters().OrderBy(p => p.Position).Select(t => t.ParameterType).ToArray()
                    );

            result.SetImplementationFlags(MethodImplAttributes.AggressiveInlining);

            var generator = result.GetILGenerator();
            var fieldName = LibraryInterfaceMapper.GetFieldNameForMethodInfo(overrideMethod);
            var field = fieldBuilders.First(f => f.Name == fieldName);
            var parameters = overrideMethod.GetParameters();
            OnInvokeBegin(owner, interfaceType, generator, overrideMethod);
            generator.Emit(OpCodes.Ldarg_0); //  this
            generator.Emit(OpCodes.Ldfld, field); // MethodNameProc _glMethodName. Initialized by constructor.
            foreach (var item in parameters.Where(p => !p.IsRetval).Select((p, i) => new { Type = p, Index = i }))
            {
                generator.Emit(OpCodes.Ldarg, item.Index + 1);
            }

            generator.EmitCall(OpCodes.Callvirt, field.FieldType.GetMethod("Invoke"), null);

            OnInvokeEnd(owner, interfaceType, generator, overrideMethod);

            generator.Emit(OpCodes.Ret);

            owner.DefineMethodOverride(result, overrideMethod);

            return result;
        }
开发者ID:GeirGrusom,项目名称:PlatformInvoker,代码行数:43,代码来源:DefaultMethodCallWrapper.cs


示例7: createProperty

 /// <summary>
 /// 动态创建类的属性
 /// </summary>
 /// <param name="tb">承载该属性的类型</param>
 /// <param name="properityName">属性名,首字母应大写</param>
 /// <param name="properityType">属性数据类型</param>
 public static FieldBuilder createProperty(TypeBuilder tb, string propertyName, Type propertyType)
 {
     //定义属性对应的私有字段
     FieldBuilder fieldBuilder = tb.DefineField("_" + propertyName, propertyType, FieldAttributes.Private);
     //定义属性
     PropertyBuilder propertyBuilder = tb.DefineProperty(propertyName, PropertyAttributes.HasDefault, propertyType, null);
     //定义与属性相关的get方法
     MethodBuilder getPropMthdBldr = tb.DefineMethod("get_" + propertyName,
         MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig,
         propertyType,
         Type.EmptyTypes);
     ILGenerator getIL = getPropMthdBldr.GetILGenerator();//获取il 生成器
     getIL.Emit(OpCodes.Ldarg_0);
     getIL.Emit(OpCodes.Ldfld, fieldBuilder);
     getIL.Emit(OpCodes.Ret);
     //定义与属性相关的set方法
     MethodBuilder setPropMthdBldr = tb.DefineMethod("set_" + propertyName,
         MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig,
         null, new Type[] { propertyType });
     ILGenerator setIL = setPropMthdBldr.GetILGenerator();
     /*
      * OpCodes.Ldarg_0:Ldarg是加载方法参数的意思。这里Ldarg_0事实上是对当前对象的引用即this。
      * 因为类的实例方法(非静态方法)在调用时,this 是会作为第一个参数传入的。
      */
     setIL.Emit(OpCodes.Ldarg_0);
     setIL.Emit(OpCodes.Ldarg_1);//OpCodes.Ldarg_1:加载参数列表的第一个参数了。
     setIL.Emit(OpCodes.Stfld, fieldBuilder);//OpCodes.Stfld:用新值替换在对象引用或指针的字段中存储的值。
     setIL.Emit(OpCodes.Ret);
     //把get/set方法和属性联系起来
     propertyBuilder.SetGetMethod(getPropMthdBldr);
     propertyBuilder.SetSetMethod(setPropMthdBldr);
     return fieldBuilder;
 }
开发者ID:lsunflower,项目名称:ORM,代码行数:39,代码来源:CustomDynamicBuilder.cs


示例8: IntroductionProxyMethodBuilder

 /// <summary>
 /// Creates a new instance of the method builder.
 /// </summary>
 /// <param name="typeBuilder">The type builder to use.</param>
 /// <param name="aopProxyGenerator">
 /// The <see cref="IAopProxyTypeGenerator"/> implementation to use.
 /// </param>
 /// <param name="targetMethods">
 /// 
 /// </param>
 /// <param name="index">index of the introduction to delegate call to</param>
 public IntroductionProxyMethodBuilder(
     TypeBuilder typeBuilder, IAopProxyTypeGenerator aopProxyGenerator,
     IDictionary targetMethods, int index)
     : base(typeBuilder, aopProxyGenerator, true, targetMethods)
 {
     this.index = index;
 }
开发者ID:Binodesk,项目名称:spring-net,代码行数:18,代码来源:IntroductionProxyMethodBuilder.cs


示例9: DefineInterface

        public static void DefineInterface(TypeBuilder typeBuilder, Type interfaceType, Type implementType,
            Action<ILGenerator, MethodInfo, MethodInfo> ilGenerator)
        {
            var proxyMethodBuilder = new ProxyMethodBuilder(typeBuilder);
            InterfaceMapping mapping = implementType.GetInterfaceMap(interfaceType);
            for (int i = 0; i < mapping.InterfaceMethods.Length; i++)
                mapping.TargetMethods[i] = proxyMethodBuilder.DefineMethod(mapping.InterfaceMethods[i],
                    il => ilGenerator(il, mapping.InterfaceMethods[i], mapping.TargetMethods[i]));

            foreach (PropertyInfo propertyInfo in interfaceType.GetProperties())
            {
                MethodBuilder getMethodBuilder = null;
                MethodInfo getMethodInfo = propertyInfo.GetGetMethod();
                if (getMethodInfo != null)
                    getMethodBuilder = (MethodBuilder)GetTargetMethodInfo(ref mapping, getMethodInfo);

                MethodBuilder setMethodBuilder = null;
                MethodInfo setMethodInfo = propertyInfo.GetSetMethod();
                if (setMethodInfo != null)
                    setMethodBuilder = (MethodBuilder)GetTargetMethodInfo(ref mapping, setMethodInfo);

                ProxyBuilderHelper.DefineProperty(typeBuilder, propertyInfo, getMethodBuilder, setMethodBuilder);
            }

            foreach (EventInfo eventInfo in interfaceType.GetEvents())
            {
                var addMethodBuilder = (MethodBuilder)GetTargetMethodInfo(ref mapping, eventInfo.GetAddMethod());
                var removeMethodBuilder = (MethodBuilder)GetTargetMethodInfo(ref mapping, eventInfo.GetRemoveMethod());
                ProxyBuilderHelper.DefineEvent(typeBuilder, eventInfo, addMethodBuilder, removeMethodBuilder);
            }
        }
开发者ID:voronov-maxim,项目名称:ProxyMixin,代码行数:31,代码来源:ProxyBuilderHelper.cs


示例10: GenerateProperties

        private static FieldInfo[] GenerateProperties(TypeBuilder tb, IDictionary<string, Type> properties)
        {
            const MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig;

            FieldInfo[] fields = new FieldBuilder[properties.Count];
            int i = 0;
            foreach (string key in properties.Keys)
            {
                string name = key;
                Type type = properties[key];
                FieldBuilder fb = tb.DefineField("_" + key, type, FieldAttributes.Public);
                PropertyBuilder pb = tb.DefineProperty(key, PropertyAttributes.HasDefault, type, null);
                
                MethodBuilder mbGet = tb.DefineMethod("get_" + name, getSetAttr, type, Type.EmptyTypes);
                ILGenerator genGet = mbGet.GetILGenerator(8);
                genGet.Emit(OpCodes.Ldarg_0);
                genGet.Emit(OpCodes.Ldfld, fb);
                genGet.Emit(OpCodes.Ret);
                pb.SetGetMethod(mbGet);

                MethodBuilder mbSet = tb.DefineMethod("set_" + name, getSetAttr, null, new Type[] { type });
                ILGenerator genSet = mbSet.GetILGenerator(8);
                genSet.Emit(OpCodes.Ldarg_0);
                genSet.Emit(OpCodes.Ldarg_1);
                genSet.Emit(OpCodes.Stfld, fb);
                genSet.Emit(OpCodes.Ret);
                pb.SetSetMethod(mbSet);

                fields[i] = fb;
            }

            return fields;
        }
开发者ID:StefH,项目名称:System.Linq.Dynamic,代码行数:33,代码来源:Fact.cs


示例11: ImplementProxy

		public void ImplementProxy(TypeBuilder typeBuilder)
		{
			typeBuilder.AddInterfaceImplementation(typeof (IProxy));
			InterceptorField = typeBuilder
				.DefineField("__interceptor",
							 typeof (Proxy.DynamicProxy.IInterceptor),
							 FieldAttributes.Private);
			var getterMethod = typeBuilder
				.DefineMethod("get_Interceptor",
							  InterceptorMethodsAttributes,
							  CallingConventions.HasThis,
							  typeof (Proxy.DynamicProxy.IInterceptor),
							  new System.Type[0]);
			getterMethod.SetImplementationFlags(MethodImplAttributes.IL);
			var il = getterMethod.GetILGenerator();
			il.Emit(OpCodes.Ldarg_0);
			il.Emit(OpCodes.Ldfld, InterceptorField);
			il.Emit(OpCodes.Ret);
			var setterMethod = typeBuilder
				.DefineMethod("set_Interceptor",
							  InterceptorMethodsAttributes,
							  CallingConventions.HasThis,
							  typeof (void),
							  new[] {typeof (Proxy.DynamicProxy.IInterceptor)});
			setterMethod.SetImplementationFlags(MethodImplAttributes.IL);
			il = setterMethod.GetILGenerator();
			il.Emit(OpCodes.Ldarg_0);
			il.Emit(OpCodes.Ldarg_1);
			il.Emit(OpCodes.Stfld, InterceptorField);
			il.Emit(OpCodes.Ret);
			var originalSetter = typeof (IProxy).GetMethod("set_Interceptor");
			var originalGetter = typeof (IProxy).GetMethod("get_Interceptor");
			typeBuilder.DefineMethodOverride(setterMethod, originalSetter);
			typeBuilder.DefineMethodOverride(getterMethod, originalGetter);
		}
开发者ID:mynamespace,项目名称:NHibernate.Extensions,代码行数:35,代码来源:ProxyImplementor.cs


示例12: InterfaceImplementation

 public InterfaceImplementation(
     TypeBuilder typeBuilder,
     Type @interface,
     FieldBuilder proxyInterceptionPipelineField,
     bool explicitImplementation)
     : this(typeBuilder, @interface, proxyInterceptionPipelineField, explicitImplementation, null)
 { }
开发者ID:shhyder,项目名称:MapApplication,代码行数:7,代码来源:InterfaceImplementation.cs


示例13: GenerateProperties

		private FieldInfo[] GenerateProperties(TypeBuilder tb, DynamicProperty[] properties)
		{
			FieldInfo[] array = new FieldBuilder[properties.Length];
			for (int i = 0; i < properties.Length; i++)
			{
				DynamicProperty dynamicProperty = properties[i];
				FieldBuilder fieldBuilder = tb.DefineField("_" + dynamicProperty.Name, dynamicProperty.Type, FieldAttributes.Private);
				PropertyBuilder propertyBuilder = tb.DefineProperty(dynamicProperty.Name, PropertyAttributes.HasDefault, dynamicProperty.Type, null);
				MethodBuilder methodBuilder = tb.DefineMethod("get_" + dynamicProperty.Name, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.HideBySig | MethodAttributes.SpecialName, dynamicProperty.Type, Type.EmptyTypes);
				ILGenerator iLGenerator = methodBuilder.GetILGenerator();
				iLGenerator.Emit(OpCodes.Ldarg_0);
				iLGenerator.Emit(OpCodes.Ldfld, fieldBuilder);
				iLGenerator.Emit(OpCodes.Ret);
				MethodBuilder methodBuilder2 = tb.DefineMethod("set_" + dynamicProperty.Name, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.HideBySig | MethodAttributes.SpecialName, null, new Type[]
				{
					dynamicProperty.Type
				});
				ILGenerator iLGenerator2 = methodBuilder2.GetILGenerator();
				iLGenerator2.Emit(OpCodes.Ldarg_0);
				iLGenerator2.Emit(OpCodes.Ldarg_1);
				iLGenerator2.Emit(OpCodes.Stfld, fieldBuilder);
				iLGenerator2.Emit(OpCodes.Ret);
				propertyBuilder.SetGetMethod(methodBuilder);
				propertyBuilder.SetSetMethod(methodBuilder2);
				array[i] = fieldBuilder;
			}
			return array;
		}
开发者ID:charreal,项目名称:Jq.Grid,代码行数:28,代码来源:ClassFactory.cs


示例14: BuildStringProperty

        private static void BuildStringProperty(TypeBuilder typeBuilder, string property)
        {
            //implement properties from interface
            FieldBuilder fieldBuilder = typeBuilder.DefineField(property.ToLower(), typeof(string), FieldAttributes.Private);
            PropertyBuilder propertyBuilder = typeBuilder.DefineProperty(property, PropertyAttributes.HasDefault, typeof(string), null);
            const MethodAttributes getSetAttributes = MethodAttributes.Public | MethodAttributes.SpecialName |
                                                      MethodAttributes.HideBySig | MethodAttributes.Virtual;
            //define 'get' accessor
            MethodBuilder getPropertyBuilder = typeBuilder.DefineMethod("get_" + property, getSetAttributes, typeof(string),
                                                                        Type.EmptyTypes);
            //create IL code for get
            ILGenerator genusGetIL = getPropertyBuilder.GetILGenerator();
            genusGetIL.Emit(OpCodes.Ldarg_0);
            genusGetIL.Emit(OpCodes.Ldfld, fieldBuilder);
            genusGetIL.Emit(OpCodes.Ret);

            //define 'set' accessor
            MethodBuilder setPropertyBuilder = typeBuilder.DefineMethod("set_" + property, getSetAttributes, null,
                                                                        new[] { typeof(String) });
            //create IL code for set
            ILGenerator genusSetIL = setPropertyBuilder.GetILGenerator();
            genusSetIL.Emit(OpCodes.Ldarg_0);
            genusSetIL.Emit(OpCodes.Ldarg_1);
            genusSetIL.Emit(OpCodes.Stfld, fieldBuilder);
            genusSetIL.Emit(OpCodes.Ret);

            //map get and set to property 'methods'
            propertyBuilder.SetGetMethod(getPropertyBuilder);
            propertyBuilder.SetSetMethod(setPropertyBuilder);
        }
开发者ID:CoronaFiredancer,项目名称:basicoperations,代码行数:30,代码来源:TypeFactory.cs


示例15: CreateProperty

        private static void CreateProperty(string name, TypeBuilder tb, MethodInfo bgcmi, MethodInfo bscmi)
        {
            // define getter
            var gmb = tb.DefineMethod("get_" + name,
                MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Public,
                typeof(string),
                null);

            var g = gmb.GetILGenerator();
            g.Emit(OpCodes.Ldarg_0);
            g.Emit(OpCodes.Ldstr, name);
            g.Emit(OpCodes.Call, bgcmi);
            g.Emit(OpCodes.Ret);

            // define setter
            var smb = tb.DefineMethod("set_" + name,
                MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Public,
                null,
                new Type[] { typeof(string) });

            g = smb.GetILGenerator();
            g.Emit(OpCodes.Ldarg_0);
            g.Emit(OpCodes.Ldstr, name);
            g.Emit(OpCodes.Ldarg_1);
            g.Emit(OpCodes.Call, bscmi);
            g.Emit(OpCodes.Ret);

            // define properties
            var pb = tb.DefineProperty(name, PropertyAttributes.None, typeof(string), null);
            pb.SetGetMethod(gmb);
            pb.SetSetMethod(smb);
        }
开发者ID:jflam,项目名称:spreadsheet,代码行数:32,代码来源:ViewModel.cs


示例16: ResolveType

        public static EventBrokerResolvedType ResolveType(IMemberMap<EventInfo> memberMap, TypeBuilder typeBuilder)
        {
            Type[] @params = null;
            Type delegateType = null;
            Type[] delegateParameters = null;
            var @event = memberMap.ContractMember;
            var declaringType = memberMap.ContractType;
            var invokeMethod = @event.GetInvokeMethod();
            var invokeReturnType = invokeMethod.ReturnType;
            var eventBrokerResolvedType = new EventBrokerResolvedType(@event) {
                DecalringType = declaringType
            };

            if (invokeMethod.GetDelegateParams(out @params, out delegateParameters)) {
                delegateType = @params.GetDelegateType(true);
                eventBrokerResolvedType.EventInterceptionContractArgs = @event.ToEventArgumentContract(@params);
                eventBrokerResolvedType.EventInterceptionArgs = declaringType.MakeGenericFunctionAspectArgsEvent(@params);
                eventBrokerResolvedType.EventBrokerBaseClassType = declaringType.MakeGenericEventBrokerBaseClassFunctionBinding(@params);
                eventBrokerResolvedType.EventBrokerInvokeDelegateType = typeof(Func<,>).MakeGenericType(new[] { eventBrokerResolvedType.EventInterceptionContractArgs, invokeReturnType });
            }
            else {
                delegateType = delegateParameters.GetDelegateType(false);
                eventBrokerResolvedType.EventInterceptionContractArgs = @event.ToEventArgumentContract(delegateParameters);
                eventBrokerResolvedType.EventInterceptionArgs = declaringType.MakeGenericActionAspectArgsEvent(delegateParameters);
                eventBrokerResolvedType.EventBrokerBaseClassType = declaringType.MakeGenericEventBrokerBaseClassActionType(delegateParameters);
                eventBrokerResolvedType.EventBrokerInvokeDelegateType = typeof(Action<>).MakeGenericType(new[] { eventBrokerResolvedType.EventInterceptionContractArgs });
            }

            eventBrokerResolvedType.Arguments = delegateParameters;
            eventBrokerResolvedType.EventBrokerFieldType = typeof(IEventBroker<>).MakeGenericType(delegateType);

            return eventBrokerResolvedType;
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:33,代码来源:EventBrokerFieldTypeDefinitionResolver.cs


示例17: ImplementInterfaceMethod

        private static void ImplementInterfaceMethod(TypeBuilder newType, MethodInfo interfaceMethod)
        {
            ParameterInfo[] parameters = interfaceMethod.GetParameters();
            Type[] parameterTypes = new Type[parameters.Length];
            for (int idx = 0; idx < parameters.Length; idx++)
                parameterTypes[idx] = parameters[idx].ParameterType;

            MethodBuilder newMethod = newType.DefineMethod(
                interfaceMethod.DeclaringType.Name + "." + interfaceMethod.Name,
                MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final,
                interfaceMethod.ReturnType, parameterTypes
            );

            MethodInfo baseMethod = newType.BaseType.GetMethod(interfaceMethod.Name, parameterTypes);

            for (int i = 0; i < parameters.Length; i++)
                newMethod.DefineParameter(i + 1, parameters[i].Attributes, parameters[i].Name);

            ILGenerator ilGen = newMethod.GetILGenerator();

            for (int i = 0; i <= parameterTypes.Length; i++)
                ilGen.Emit(OpCodes.Ldarg_S, (byte)i);

            ilGen.Emit(OpCodes.Call, baseMethod);
            ilGen.Emit(OpCodes.Ret);

            newType.DefineMethodOverride(newMethod, interfaceMethod);
        }
开发者ID:JoB70,项目名称:xunit,代码行数:28,代码来源:DynamicTypeGenerator.cs


示例18: GenerateCode

        public override void GenerateCode(ILGenerator codeGenerator, TypeBuilder typeBuilder, ModuleBuilder moduleBuilder)
        {
            LeftOperand.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);
            RightOperand.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);

            Label endLabel = codeGenerator.DefineLabel();
            Label trueLabel = codeGenerator.DefineLabel();

            if (LeftOperand.ReturnType == StringType.StringInstance)
            {
                codeGenerator.Emit(OpCodes.Call, typeof(String).GetMethod("CompareTo", new Type[] { typeof(string) }));
                codeGenerator.Emit(OpCodes.Ldc_I4_0);
                codeGenerator.Emit(OpCodes.Bne_Un, trueLabel);
            }
            else
                codeGenerator.Emit(OpCodes.Bne_Un, trueLabel);

            codeGenerator.Emit(OpCodes.Ldc_I4_0);
            codeGenerator.Emit(OpCodes.Br, endLabel);

            codeGenerator.MarkLabel(trueLabel);
            codeGenerator.Emit(OpCodes.Ldc_I4_1);

            codeGenerator.MarkLabel(endLabel);
        }
开发者ID:sandygk,项目名称:Tiger-Compiler,代码行数:25,代码来源:NotEqNode.cs


示例19: CreateType

 public Type CreateType(TypeBuilder typeBuilder)
 {
     Type proxyType = typeBuilder.CreateType();
     ((AssemblyBuilder)typeBuilder.Assembly).Save("ProxyAssembly.dll");
     AssemblyAssert.IsValidAssembly("ProxyAssembly.dll");
     return proxyType;
 }
开发者ID:jarlef,项目名称:LightInject,代码行数:7,代码来源:VerifiableTypeBuilderFactory.cs


示例20: ProxyClassBuildingContext

 public ProxyClassBuildingContext(Type interfaceType, string path, TypeBuilder builder, ProxyClassFieldCache fields)
 {
     Fields = fields;
     Builder = builder;
     Path = path;
     InterfaceType = interfaceType;
 }
开发者ID:yonglehou,项目名称:SharpRPC,代码行数:7,代码来源:ProxyClassBuildingContext.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Internal.MemoryBlock类代码示例发布时间:2022-05-26
下一篇:
C# Emit.SignatureHelper类代码示例发布时间: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