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

C# Emit.TypeBuilder类代码示例

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

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



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


示例16: ConstructorForwarder

 internal ConstructorForwarder(TypeWrapperFactory context, TypeBuilder typeBuilder, MethodWrapper ctor)
     : base(ctor.DeclaringType, ctor.Name, ctor.Signature, null, null, null, ctor.Modifiers, MemberFlags.None)
 {
     this.context = context;
     this.typeBuilder = typeBuilder;
     this.ctor = ctor;
 }
开发者ID:T0pp3r,项目名称:ikvm-fork,代码行数:7,代码来源:AotTypeWrapper.cs


示例17: GenericTypeParameterBuilder

		internal GenericTypeParameterBuilder(string name, TypeBuilder type, int position)
			: this(name, type, null, position, Signature.ELEMENT_TYPE_VAR)
		{
		}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:4,代码来源:TypeBuilder.cs


示例18: EnumBuilder

		internal EnumBuilder(TypeBuilder typeBuilder, FieldBuilder fieldBuilder)
			: base(typeBuilder)
		{
			this.typeBuilder = typeBuilder;
			this.fieldBuilder = fieldBuilder;
		}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:6,代码来源:EnumBuilder.cs


示例19: RemapperTypeWrapper

			internal RemapperTypeWrapper(CompilerClassLoader classLoader, IKVM.Internal.MapXml.Class c, IKVM.Internal.MapXml.Root map)
				: base((Modifiers)c.Modifiers, c.Name)
			{
				this.classLoader = classLoader;
				this.baseTypeWrapper = GetBaseWrapper(c);
				classDef = c;
				bool baseIsSealed = false;
				shadowType = StaticCompiler.Universe.GetType(c.Shadows, true);
				classLoader.SetRemappedType(shadowType, this);
				Type baseType = shadowType;
				Type baseInterface = null;
				if(baseType.IsInterface)
				{
					baseInterface = baseType;
				}
				TypeAttributes attrs = TypeAttributes.Public;
				if((c.Modifiers & IKVM.Internal.MapXml.MapModifiers.Interface) == 0)
				{
					attrs |= TypeAttributes.Class;
					if(baseType.IsSealed)
					{
						baseIsSealed = true;
						attrs |= TypeAttributes.Abstract | TypeAttributes.Sealed;
					}
				}
				else
				{
					attrs |= TypeAttributes.Interface | TypeAttributes.Abstract;
					baseType = null;
				}
				if((c.Modifiers & IKVM.Internal.MapXml.MapModifiers.Abstract) != 0)
				{
					attrs |= TypeAttributes.Abstract;
				}
				string name = c.Name.Replace('/', '.');
				typeBuilder = classLoader.GetTypeWrapperFactory().ModuleBuilder.DefineType(name, attrs, baseIsSealed ? Types.Object : baseType);
				if(c.Attributes != null)
				{
					foreach(IKVM.Internal.MapXml.Attribute custattr in c.Attributes)
					{
						AttributeHelper.SetCustomAttribute(classLoader, typeBuilder, custattr);
					}
				}
				if(baseInterface != null)
				{
					typeBuilder.AddInterfaceImplementation(baseInterface);
				}
				if(classLoader.EmitStackTraceInfo)
				{
					AttributeHelper.SetSourceFile(typeBuilder, Path.GetFileName(classLoader.options.remapfile));
				}

				if(baseIsSealed)
				{
					AttributeHelper.SetModifiers(typeBuilder, (Modifiers)c.Modifiers, false);
				}

				if(c.scope == IKVM.Internal.MapXml.Scope.Public)
				{
					// FXBUG we would like to emit an attribute with a Type argument here, but that doesn't work because
					// of a bug in SetCustomAttribute that causes type arguments to be serialized incorrectly (if the type
					// is in the same assembly). Normally we use AttributeHelper.FreezeDry to get around this, but that doesn't
					// work in this case (no attribute is emitted at all). So we work around by emitting a string instead
					AttributeHelper.SetRemappedClass(classLoader.assemblyBuilder, name, shadowType);
						
					AttributeHelper.SetRemappedType(typeBuilder, shadowType);
				}

				List<MethodWrapper> methods = new List<MethodWrapper>();

				if(c.Constructors != null)
				{
					foreach(IKVM.Internal.MapXml.Constructor m in c.Constructors)
					{
						methods.Add(new RemappedConstructorWrapper(this, m));
					}
				}

				if(c.Methods != null)
				{
					foreach(IKVM.Internal.MapXml.Method m in c.Methods)
					{
						methods.Add(new RemappedMethodWrapper(this, m, map, false));
					}
				}
				// add methods from our super classes (e.g. Throwable should have Object's methods)
				if(!this.IsFinal && !this.IsInterface && this.BaseTypeWrapper != null)
				{
					foreach(MethodWrapper mw in BaseTypeWrapper.GetMethods())
					{
						RemappedMethodWrapper rmw = mw as RemappedMethodWrapper;
						if(rmw != null && (rmw.IsPublic || rmw.IsProtected))
						{
							if(!FindMethod(methods, rmw.Name, rmw.Signature))
							{
								methods.Add(new RemappedMethodWrapper(this, rmw.XmlMethod, map, true));
							}
						}
					}
				}
//.........这里部分代码省略.........
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:101,代码来源:CompilerClassLoader.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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