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


C# Emit.TypeBuilder类代码示例

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


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

示例1: EventBuilder

		internal EventBuilder(TypeBuilder typeBuilder, string name, EventAttributes attributes, Type eventtype)
		{
			this.typeBuilder = typeBuilder;
			this.name = name;
			this.attributes = attributes;
			this.eventtype = typeBuilder.ModuleBuilder.GetTypeTokenForMemberRef(eventtype);
		}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:7,代码来源:EventBuilder.cs

示例2: PropertyBuilder

		internal PropertyBuilder(TypeBuilder typeBuilder, string name, PropertyAttributes attributes, PropertySignature sig, bool patchCallingConvention)
		{
			this.typeBuilder = typeBuilder;
			this.name = name;
			this.attributes = attributes;
			this.sig = sig;
			this.patchCallingConvention = patchCallingConvention;
		}
开发者ID:ngraziano,项目名称:mono,代码行数:8,代码来源:PropertyBuilder.cs

示例3: FieldBuilder

		internal FieldBuilder(TypeBuilder type, string name, Type fieldType, CustomModifiers customModifiers, FieldAttributes attribs)
		{
			this.typeBuilder = type;
			this.name = name;
			this.pseudoToken = type.ModuleBuilder.AllocPseudoToken();
			this.nameIndex = type.ModuleBuilder.Strings.Add(name);
			this.fieldSig = FieldSignature.Create(fieldType, customModifiers);
			ByteBuffer sig = new ByteBuffer(5);
			fieldSig.WriteSig(this.typeBuilder.ModuleBuilder, sig);
			this.signature = this.typeBuilder.ModuleBuilder.Blobs.Add(sig);
			this.attribs = attribs;
			this.typeBuilder.ModuleBuilder.Field.AddVirtualRecord();
		}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:13,代码来源:FieldBuilder.cs

示例4: DefineGhostMethod

		protected override MethodBuilder DefineGhostMethod(TypeBuilder typeBuilder, string name, MethodAttributes attribs, MethodWrapper mw)
		{
			if(typeBuilderGhostInterface != null && mw.IsVirtual)
			{
				DefineMethodHelper helper = mw.GetDefineMethodHelper();
				MethodBuilder stub = helper.DefineMethod(this, typeBuilder, name, MethodAttributes.Public);
				((GhostMethodWrapper)mw).SetGhostMethod(stub);
				return helper.DefineMethod(this, typeBuilderGhostInterface, name, attribs);
			}
			return null;
		}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:11,代码来源:AotTypeWrapper.cs

示例5: FinishGhost

        protected override void FinishGhost(TypeBuilder typeBuilder, MethodWrapper[] methods)
        {
            if(typeBuilderGhostInterface != null)
            {
                // TODO consider adding methods from base interface and java.lang.Object as well
                for(int i = 0; i < methods.Length; i++)
                {
                    // skip <clinit>
                    if(!methods[i].IsStatic)
                    {
                        TypeWrapper[] args = methods[i].GetParameters();
                        MethodBuilder stub = methods[i].GetDefineMethodHelper().DefineMethod(this, typeBuilder, methods[i].Name, MethodAttributes.Public);
                        AddParameterMetadata(stub, methods[i]);
                        AttributeHelper.SetModifiers(stub, methods[i].Modifiers, methods[i].IsInternal);
                        CodeEmitter ilgen = CodeEmitter.Create(stub);
                        CodeEmitterLabel end = ilgen.DefineLabel();
                        TypeWrapper[] implementers = classLoader.GetGhostImplementers(this);
                        ilgen.Emit(OpCodes.Ldarg_0);
                        ilgen.Emit(OpCodes.Ldfld, ghostRefField);
                        ilgen.Emit(OpCodes.Dup);
                        ilgen.Emit(OpCodes.Isinst, typeBuilderGhostInterface);
                        CodeEmitterLabel label = ilgen.DefineLabel();
                        ilgen.EmitBrfalse(label);
                        ilgen.Emit(OpCodes.Castclass, typeBuilderGhostInterface);
                        for(int k = 0; k < args.Length; k++)
                        {
                            ilgen.EmitLdarg(k + 1);
                        }
                        ilgen.Emit(OpCodes.Callvirt, (MethodInfo)methods[i].GetMethod());
                        ilgen.EmitBr(end);
                        ilgen.MarkLabel(label);
                        for(int j = 0; j < implementers.Length; j++)
                        {
                            ilgen.Emit(OpCodes.Dup);
                            ilgen.Emit(OpCodes.Isinst, implementers[j].TypeAsTBD);
                            label = ilgen.DefineLabel();
                            ilgen.EmitBrfalse(label);
                            ilgen.Emit(OpCodes.Castclass, implementers[j].TypeAsTBD);
                            for(int k = 0; k < args.Length; k++)
                            {
                                ilgen.EmitLdarg(k + 1);
                            }
                            MethodWrapper mw = implementers[j].GetMethodWrapper(methods[i].Name, methods[i].Signature, true);
                            mw.EmitCallvirt(ilgen);
                            ilgen.EmitBr(end);
                            ilgen.MarkLabel(label);
                        }
                        // we need to do a null check (null fails all the isinst checks)
                        ilgen.EmitNullCheck();
                        ilgen.EmitThrow("java.lang.IncompatibleClassChangeError", Name);
                        ilgen.MarkLabel(end);
                        ilgen.Emit(OpCodes.Ret);
                        ilgen.DoEmit();
                    }
                }
                // HACK create a scope to enable reuse of "implementers" name
                if(true)
                {
                    MethodBuilder mb;
                    CodeEmitter ilgen;
                    CodeEmitterLocal local;
                    // add implicit conversions for all the ghost implementers
                    TypeWrapper[] implementers = classLoader.GetGhostImplementers(this);
                    for(int i = 0; i < implementers.Length; i++)
                    {
                        mb = typeBuilder.DefineMethod("op_Implicit", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.SpecialName, TypeAsSignatureType, new Type[] { implementers[i].TypeAsSignatureType });
                        AttributeHelper.HideFromJava(mb);
                        ilgen = CodeEmitter.Create(mb);
                        local = ilgen.DeclareLocal(TypeAsSignatureType);
                        ilgen.Emit(OpCodes.Ldloca, local);
                        ilgen.Emit(OpCodes.Ldarg_0);
                        ilgen.Emit(OpCodes.Stfld, ghostRefField);
                        ilgen.Emit(OpCodes.Ldloca, local);
                        ilgen.Emit(OpCodes.Ldobj, TypeAsSignatureType);
                        ilgen.Emit(OpCodes.Ret);
                        ilgen.DoEmit();
                    }
                    // Implement the "IsInstance" method
                    mb = ghostIsInstanceMethod;
                    AttributeHelper.HideFromJava(mb);
                    ilgen = CodeEmitter.Create(mb);
                    CodeEmitterLabel end = ilgen.DefineLabel();
                    for(int i = 0; i < implementers.Length; i++)
                    {
                        ilgen.Emit(OpCodes.Ldarg_0);
                        ilgen.Emit(OpCodes.Isinst, implementers[i].TypeAsTBD);
                        CodeEmitterLabel label = ilgen.DefineLabel();
                        ilgen.EmitBrfalse(label);
                        ilgen.Emit(OpCodes.Ldc_I4_1);
                        ilgen.EmitBr(end);
                        ilgen.MarkLabel(label);
                    }
                    ilgen.Emit(OpCodes.Ldarg_0);
                    ilgen.Emit(OpCodes.Isinst, typeBuilderGhostInterface);
                    ilgen.Emit(OpCodes.Ldnull);
                    ilgen.Emit(OpCodes.Cgt_Un);
                    ilgen.MarkLabel(end);
                    ilgen.Emit(OpCodes.Ret);
                    ilgen.DoEmit();
                    // Implement the "IsInstanceArray" method
//.........这里部分代码省略.........
开发者ID:T0pp3r,项目名称:ikvm-fork,代码行数:101,代码来源:AotTypeWrapper.cs

示例6: EmitMapXmlMetadata

 protected override void EmitMapXmlMetadata(TypeBuilder typeBuilder, ClassFile classFile, FieldWrapper[] fields, MethodWrapper[] methods)
 {
     Dictionary<string, IKVM.Internal.MapXml.Class> mapxml = classLoader.GetMapXmlClasses();
     if(mapxml != null)
     {
         IKVM.Internal.MapXml.Class clazz;
         if(mapxml.TryGetValue(classFile.Name, out clazz))
         {
             if(clazz.Attributes != null)
             {
                 PublishAttributes(typeBuilder, clazz);
             }
             if(clazz.Properties != null)
             {
                 PublishProperties(typeBuilder, clazz);
             }
             if(clazz.Fields != null)
             {
                 foreach(IKVM.Internal.MapXml.Field field in clazz.Fields)
                 {
                     if(field.Attributes != null)
                     {
                         foreach(FieldWrapper fw in fields)
                         {
                             if(fw.Name == field.Name && fw.Signature == field.Sig)
                             {
                                 FieldBuilder fb = fw.GetField() as FieldBuilder;
                                 if(fb != null)
                                 {
                                     foreach(IKVM.Internal.MapXml.Attribute attr in field.Attributes)
                                     {
                                         AttributeHelper.SetCustomAttribute(classLoader, fb, attr);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if(clazz.Constructors != null)
             {
                 // HACK this isn't the right place to do this, but for now it suffices
                 foreach(IKVM.Internal.MapXml.Constructor constructor in clazz.Constructors)
                 {
                     // are we adding a new constructor?
                     if(GetMethodWrapper(StringConstants.INIT, constructor.Sig, false) == null)
                     {
                         if(constructor.body == null)
                         {
                             Console.Error.WriteLine("Error: Constructor {0}.<init>{1} in xml remap file doesn't have a body.", clazz.Name, constructor.Sig);
                             continue;
                         }
                         bool setmodifiers = false;
                         MethodAttributes attribs = 0;
                         MapModifiers(constructor.Modifiers, true, out setmodifiers, ref attribs);
                         Type returnType;
                         Type[] parameterTypes;
                         MapSignature(constructor.Sig, out returnType, out parameterTypes);
                         MethodBuilder cb = ReflectUtil.DefineConstructor(typeBuilder, attribs, parameterTypes);
                         if(setmodifiers)
                         {
                             AttributeHelper.SetModifiers(cb, (Modifiers)constructor.Modifiers, false);
                         }
                         CompilerClassLoader.AddDeclaredExceptions(cb, constructor.throws);
                         CodeEmitter ilgen = CodeEmitter.Create(cb);
                         constructor.Emit(classLoader, ilgen);
                         ilgen.DoEmit();
                         if(constructor.Attributes != null)
                         {
                             foreach(IKVM.Internal.MapXml.Attribute attr in constructor.Attributes)
                             {
                                 AttributeHelper.SetCustomAttribute(classLoader, cb, attr);
                             }
                         }
                     }
                 }
                 foreach(IKVM.Internal.MapXml.Constructor constructor in clazz.Constructors)
                 {
                     if(constructor.Attributes != null)
                     {
                         foreach(MethodWrapper mw in methods)
                         {
                             if(mw.Name == "<init>" && mw.Signature == constructor.Sig)
                             {
                                 MethodBuilder mb = mw.GetMethod() as MethodBuilder;
                                 if(mb != null)
                                 {
                                     foreach(IKVM.Internal.MapXml.Attribute attr in constructor.Attributes)
                                     {
                                         AttributeHelper.SetCustomAttribute(classLoader, mb, attr);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if(clazz.Methods != null)
             {
                 // HACK this isn't the right place to do this, but for now it suffices
//.........这里部分代码省略.........
开发者ID:T0pp3r,项目名称:ikvm-fork,代码行数:101,代码来源:AotTypeWrapper.cs

示例7: DefineGhostType

 protected override TypeBuilder DefineGhostType(string mangledTypeName, TypeAttributes typeAttribs)
 {
     typeAttribs &= ~(TypeAttributes.Interface | TypeAttributes.Abstract);
     typeAttribs |= TypeAttributes.Class | TypeAttributes.Sealed;
     TypeBuilder typeBuilder = classLoader.GetTypeWrapperFactory().ModuleBuilder.DefineType(mangledTypeName, typeAttribs, Types.ValueType);
     AttributeHelper.SetGhostInterface(typeBuilder);
     AttributeHelper.SetModifiers(typeBuilder, Modifiers, IsInternal);
     ghostRefField = typeBuilder.DefineField("__<ref>", Types.Object, FieldAttributes.Public | FieldAttributes.SpecialName);
     typeBuilderGhostInterface = typeBuilder.DefineNestedType("__Interface", TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.NestedPublic);
     AttributeHelper.HideFromJava(typeBuilderGhostInterface);
     ghostIsInstanceMethod = typeBuilder.DefineMethod("IsInstance", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, Types.Boolean, new Type[] { Types.Object });
     ghostIsInstanceMethod.DefineParameter(1, ParameterAttributes.None, "obj");
     ghostIsInstanceArrayMethod = typeBuilder.DefineMethod("IsInstanceArray", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, Types.Boolean, new Type[] { Types.Object, Types.Int32 });
     ghostIsInstanceArrayMethod.DefineParameter(1, ParameterAttributes.None, "obj");
     ghostIsInstanceArrayMethod.DefineParameter(2, ParameterAttributes.None, "rank");
     ghostCastMethod = typeBuilder.DefineMethod("Cast", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, typeBuilder, new Type[] { Types.Object });
     ghostCastMethod.DefineParameter(1, ParameterAttributes.None, "obj");
     ghostCastArrayMethod = typeBuilder.DefineMethod("CastArray", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, Types.Void, new Type[] { Types.Object, Types.Int32 });
     ghostCastArrayMethod.DefineParameter(1, ParameterAttributes.None, "obj");
     ghostCastArrayMethod.DefineParameter(2, ParameterAttributes.None, "rank");
     return typeBuilder;
 }
开发者ID:T0pp3r,项目名称:ikvm-fork,代码行数:22,代码来源:AotTypeWrapper.cs

示例8: WorkaroundBaseClass

 internal WorkaroundBaseClass(AotTypeWrapper wrapper, TypeBuilder typeBuilder, MethodWrapper[] methods)
 {
     this.wrapper = wrapper;
     this.typeBuilder = typeBuilder;
     this.methods = methods;
 }
开发者ID:T0pp3r,项目名称:ikvm-fork,代码行数:6,代码来源:AotTypeWrapper.cs

示例9: BakedType

		internal BakedType(TypeBuilder typeBuilder)
		{
			this.typeBuilder = typeBuilder;
		}
开发者ID:luobailiang,项目名称:mono,代码行数:4,代码来源:TypeBuilder.cs

示例10: PublishProperties

 private void PublishProperties(TypeBuilder typeBuilder, IKVM.Internal.MapXml.Class clazz)
 {
     foreach(IKVM.Internal.MapXml.Property prop in clazz.Properties)
     {
         TypeWrapper typeWrapper = GetClassLoader().RetTypeWrapperFromSigNoThrow(prop.Sig);
         TypeWrapper[] propargs = GetClassLoader().ArgTypeWrapperListFromSigNoThrow(prop.Sig);
         Type[] indexer = new Type[propargs.Length];
         for(int i = 0; i < propargs.Length; i++)
         {
             indexer[i] = propargs[i].TypeAsSignatureType;
         }
         PropertyBuilder propbuilder = typeBuilder.DefineProperty(prop.Name, PropertyAttributes.None, typeWrapper.TypeAsSignatureType, indexer);
         AttributeHelper.HideFromJava(propbuilder);
         if(prop.Attributes != null)
         {
             foreach(IKVM.Internal.MapXml.Attribute attr in prop.Attributes)
             {
                 AttributeHelper.SetCustomAttribute(classLoader, propbuilder, attr);
             }
         }
         MethodWrapper getter = null;
         MethodWrapper setter = null;
         if(prop.getter != null)
         {
             getter = GetMethodWrapper(prop.getter.Name, prop.getter.Sig, true);
             if(getter == null)
             {
                 Console.Error.WriteLine("Warning: getter not found for {0}::{1}", clazz.Name, prop.Name);
             }
         }
         if(prop.setter != null)
         {
             setter = GetMethodWrapper(prop.setter.Name, prop.setter.Sig, true);
             if(setter == null)
             {
                 Console.Error.WriteLine("Warning: setter not found for {0}::{1}", clazz.Name, prop.Name);
             }
         }
         bool final = (getter != null && getter.IsFinal) || (setter != null && setter.IsFinal);
         if(getter != null)
         {
             MethodWrapper mw = getter;
             if(!CheckPropertyArgs(mw.GetParametersForDefineMethod(), indexer) || mw.ReturnType != typeWrapper)
             {
                 Console.Error.WriteLine("Warning: ignoring invalid property getter for {0}::{1}", clazz.Name, prop.Name);
             }
             else
             {
                 MethodBuilder mb = mw.GetMethod() as MethodBuilder;
                 if(mb == null || mb.DeclaringType != typeBuilder || (!mb.IsFinal && final))
                 {
                     mb = typeBuilder.DefineMethod("get_" + prop.Name, GetPropertyMethodAttributes(mw, final), typeWrapper.TypeAsSignatureType, indexer);
                     AttributeHelper.HideFromJava(mb);
                     CodeEmitter ilgen = CodeEmitter.Create(mb);
                     if(mw.IsStatic)
                     {
                         for(int i = 0; i < indexer.Length; i++)
                         {
                             ilgen.EmitLdarg(i);
                         }
                         mw.EmitCall(ilgen);
                     }
                     else
                     {
                         ilgen.Emit(OpCodes.Ldarg_0);
                         for(int i = 0; i < indexer.Length; i++)
                         {
                             ilgen.EmitLdarg(i + 1);
                         }
                         mw.EmitCallvirt(ilgen);
                     }
                     ilgen.Emit(OpCodes.Ret);
                     ilgen.DoEmit();
                 }
                 propbuilder.SetGetMethod(mb);
             }
         }
         if(setter != null)
         {
             MethodWrapper mw = setter;
             Type[] args = new Type[indexer.Length + 1];
             indexer.CopyTo(args, 0);
             args[args.Length - 1] = typeWrapper.TypeAsSignatureType;
             if(!CheckPropertyArgs(args, mw.GetParametersForDefineMethod()))
             {
                 Console.Error.WriteLine("Warning: ignoring invalid property setter for {0}::{1}", clazz.Name, prop.Name);
             }
             else
             {
                 MethodBuilder mb = mw.GetMethod() as MethodBuilder;
                 if(mb == null || mb.DeclaringType != typeBuilder || (!mb.IsFinal && final))
                 {
                     mb = typeBuilder.DefineMethod("set_" + prop.Name, GetPropertyMethodAttributes(mw, final), mw.ReturnTypeForDefineMethod, args);
                     AttributeHelper.HideFromJava(mb);
                     CodeEmitter ilgen = CodeEmitter.Create(mb);
                     if(mw.IsStatic)
                     {
                         for(int i = 0; i <= indexer.Length; i++)
                         {
                             ilgen.EmitLdarg(i);
//.........这里部分代码省略.........
开发者ID:T0pp3r,项目名称:ikvm-fork,代码行数:101,代码来源:AotTypeWrapper.cs

示例11: PublishAttributes

 private void PublishAttributes(TypeBuilder typeBuilder, IKVM.Internal.MapXml.Class clazz)
 {
     foreach(IKVM.Internal.MapXml.Attribute attr in clazz.Attributes)
     {
         AttributeHelper.SetCustomAttribute(classLoader, typeBuilder, attr);
     }
 }
开发者ID:T0pp3r,项目名称:ikvm-fork,代码行数:7,代码来源:AotTypeWrapper.cs

示例12: CreateConstructor

 private static void CreateConstructor(TypeBuilder tb)
 {
     CodeEmitter ilgen = CodeEmitter.Create(ReflectUtil.DefineConstructor(tb, MethodAttributes.Public, new Type[] { invocationHandlerClass.TypeAsSignatureType }));
     ilgen.Emit(OpCodes.Ldarg_0);
     ilgen.Emit(OpCodes.Ldarg_1);
     proxyConstructor.EmitCall(ilgen);
     ilgen.Emit(OpCodes.Ret);
     ilgen.DoEmit();
 }
开发者ID:LogosBible,项目名称:ikvm-fork,代码行数:9,代码来源:Proxy.cs

示例13: CreateStaticInitializer

		private static void CreateStaticInitializer(TypeBuilder tb, List<ProxyMethod> methods)
		{
			ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.Static, CallingConventions.Standard, Type.EmptyTypes);
			CodeEmitter ilgen = CodeEmitter.Create(cb);
			CodeEmitterLocal callerID = ilgen.DeclareLocal([email protected]);
			TypeBuilder tbCallerID = DynamicTypeWrapper.FinishContext.EmitCreateCallerID(tb, ilgen);
			ilgen.Emit(OpCodes.Stloc, callerID);
			// HACK we shouldn't create the nested type here (the outer type must be created first)
			tbCallerID.CreateType();
			ilgen.BeginExceptionBlock();
			foreach (ProxyMethod method in methods)
			{
				method.mw.DeclaringType.EmitClassLiteral(ilgen);
				ilgen.Emit(OpCodes.Ldstr, method.mw.Name);
				TypeWrapper[] parameters = method.mw.GetParameters();
				ilgen.Emit(OpCodes.Ldc_I4, parameters.Length);
				ilgen.Emit(OpCodes.Newarr, CoreClasses.java.lang.Class.Wrapper.TypeAsArrayType);
				for (int i = 0; i < parameters.Length; i++)
				{
					ilgen.Emit(OpCodes.Dup);
					ilgen.Emit(OpCodes.Ldc_I4, i);
					parameters[i].EmitClassLiteral(ilgen);
					ilgen.Emit(OpCodes.Stelem_Ref);
				}
				if (javaLangClass_getMethod.HasCallerID)
				{
					ilgen.Emit(OpCodes.Ldloc, callerID);
				}
				javaLangClass_getMethod.EmitCallvirt(ilgen);
				ilgen.Emit(OpCodes.Stsfld, method.fb);
			}
			CodeEmitterLabel label = ilgen.DefineLabel();
			ilgen.Emit(OpCodes.Leave_S, label);
			ilgen.BeginCatchBlock(javaLangNoSuchMethodException.TypeAsExceptionType);
			javaLangThrowable_getMessage.EmitCallvirt(ilgen);
			javaLangNoClassDefFoundErrorConstructor.EmitNewobj(ilgen);
			ilgen.Emit(OpCodes.Throw);
			ilgen.EndExceptionBlock();
			ilgen.MarkLabel(label);
			ilgen.Emit(OpCodes.Ret);
			ilgen.DoEmit();
		}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:42,代码来源:Proxy.cs

示例14: CreateMethod

		private static void CreateMethod(CompilerClassLoader loader, TypeBuilder tb, ProxyMethod pm)
		{
			MethodBuilder mb = pm.mw.GetDefineMethodHelper().DefineMethod(loader.GetTypeWrapperFactory(), tb, pm.mw.Name, MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Final);
			List<string> exceptions = new List<string>();
			foreach (TypeWrapper tw in pm.exceptions)
			{
				exceptions.Add(tw.Name);
			}
			AttributeHelper.SetThrowsAttribute(mb, exceptions.ToArray());
			CodeEmitter ilgen = CodeEmitter.Create(mb);
			ilgen.BeginExceptionBlock();
			ilgen.Emit(OpCodes.Ldarg_0);
			invocationHandlerField.EmitGet(ilgen);
			ilgen.Emit(OpCodes.Ldarg_0);
			ilgen.Emit(OpCodes.Ldsfld, pm.fb);
			TypeWrapper[] parameters = pm.mw.GetParameters();
			if (parameters.Length == 0)
			{
				ilgen.Emit(OpCodes.Ldnull);
			}
			else
			{
				ilgen.Emit_Ldc_I4(parameters.Length);
				ilgen.Emit(OpCodes.Newarr, Types.Object);
				for (int i = 0; i < parameters.Length; i++)
				{
					ilgen.Emit(OpCodes.Dup);
					ilgen.Emit_Ldc_I4(i);
					ilgen.Emit(OpCodes.Ldarg, (short)i);
					if (parameters[i].IsNonPrimitiveValueType)
					{
						parameters[i].EmitBox(ilgen);
					}
					else if (parameters[i].IsPrimitive)
					{
						Boxer.EmitBox(ilgen, parameters[i]);
					}
					ilgen.Emit(OpCodes.Stelem_Ref);
				}
			}
			invokeMethod.EmitCallvirt(ilgen);
			TypeWrapper returnType = pm.mw.ReturnType;
			CodeEmitterLocal returnValue = null;
			if (returnType != PrimitiveTypeWrapper.VOID)
			{
				returnValue = ilgen.DeclareLocal(returnType.TypeAsSignatureType);
				if (returnType.IsNonPrimitiveValueType)
				{
					returnType.EmitUnbox(ilgen);
				}
				else if (returnType.IsPrimitive)
				{
					Boxer.EmitUnbox(ilgen, returnType);
				}
				else if (returnType != CoreClasses.java.lang.Object.Wrapper)
				{
					ilgen.EmitCastclass(returnType.TypeAsSignatureType);
				}
				ilgen.Emit(OpCodes.Stloc, returnValue);
			}
			CodeEmitterLabel returnLabel = ilgen.DefineLabel();
			ilgen.Emit(OpCodes.Leave, returnLabel);
			// TODO consider using a filter here (but we would need to add filter support to CodeEmitter)
			ilgen.BeginCatchBlock(Types.Exception);
			ilgen.Emit_Ldc_I4(0);
			ilgen.Emit(OpCodes.Call, ByteCodeHelperMethods.mapException.MakeGenericMethod(Types.Exception));
			CodeEmitterLocal exception = ilgen.DeclareLocal(Types.Exception);
			ilgen.Emit(OpCodes.Stloc, exception);
			CodeEmitterLabel rethrow = ilgen.DefineLabel();
			ilgen.Emit(OpCodes.Ldloc, exception);
			errorClass.EmitInstanceOf(null, ilgen);
			ilgen.Emit(OpCodes.Brtrue, rethrow);
			ilgen.Emit(OpCodes.Ldloc, exception);
			runtimeExceptionClass.EmitInstanceOf(null, ilgen);
			ilgen.Emit(OpCodes.Brtrue, rethrow);
			foreach (TypeWrapper tw in pm.exceptions)
			{
				ilgen.Emit(OpCodes.Ldloc, exception);
				tw.EmitInstanceOf(null, ilgen);
				ilgen.Emit(OpCodes.Brtrue, rethrow);
			}
			ilgen.Emit(OpCodes.Ldloc, exception);
			undeclaredThrowableExceptionConstructor.EmitNewobj(ilgen);
			ilgen.Emit(OpCodes.Throw);
			ilgen.MarkLabel(rethrow);
			ilgen.Emit(OpCodes.Rethrow);
			ilgen.EndExceptionBlock();
			ilgen.MarkLabel(returnLabel);
			if (returnValue != null)
			{
				ilgen.Emit(OpCodes.Ldloc, returnValue);
			}
			ilgen.Emit(OpCodes.Ret);
			ilgen.DoEmit();
		}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:95,代码来源:Proxy.cs

示例15: CreateConstructor

		private static void CreateConstructor(TypeBuilder tb)
		{
			ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { invocationHandlerClass.TypeAsSignatureType });
			CodeEmitter ilgen = CodeEmitter.Create(cb);
			ilgen.Emit(OpCodes.Ldarg_0);
			ilgen.Emit(OpCodes.Ldarg_1);
			proxyConstructor.EmitCall(ilgen);
			ilgen.Emit(OpCodes.Ret);
			ilgen.DoEmit();
		}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:10,代码来源:Proxy.cs


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