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


C# TypeBuilder.DefineMethodOverride方法代码示例

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


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

示例1: Override

        static ILGenerator Override(TypeBuilder type, string name)
        {
            MethodInfo baseMethod = type.BaseType.GetMethod(name, BindingFlags.NonPublic | BindingFlags.Instance);

            ParameterInfo[] parameters = baseMethod.GetParameters();
            Type[] paramTypes = new Type[parameters.Length];
            for(int i = 0 ; i < paramTypes.Length ; i++) {
                paramTypes[i] = parameters[i].ParameterType;
            }
            MethodBuilder newMethod = type.DefineMethod(baseMethod.Name,
                (baseMethod.Attributes & ~MethodAttributes.Abstract) | MethodAttributes.Final, baseMethod.CallingConvention, baseMethod.ReturnType, paramTypes);
            ILGenerator il = newMethod.GetILGenerator();
            type.DefineMethodOverride(newMethod, baseMethod);
            return il;
        }
开发者ID:SimonPStevens,项目名称:protobuf-net,代码行数:15,代码来源:RuntimeTypeModel.cs

示例2: AddDefaultInterfaceMethods

		private static void AddDefaultInterfaceMethods(DynamicTypeWrapper.FinishContext context, MethodWrapper[] methodList, TypeBuilder tb)
		{
			// we use special name to hide these from Java reflection
			const MethodAttributes attr = MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.NewSlot | MethodAttributes.Final | MethodAttributes.SpecialName;
			TypeWrapperFactory factory = context.TypeWrapper.GetClassLoader().GetTypeWrapperFactory();
			foreach (MethodWrapper mw in methodList)
			{
				if (!mw.IsAbstract)
				{
					MethodBuilder mb = mw.GetDefineMethodHelper().DefineMethod(factory, tb, mw.Name, attr);
					if (mw.Name != mw.RealName)
					{
						tb.DefineMethodOverride(mb, (MethodInfo)mw.GetMethod());
					}
					DynamicTypeWrapper.FinishContext.EmitCallDefaultInterfaceMethod(mb, mw);
				}
				else if (IsObjectMethod(mw))
				{
					MethodBuilder mb = mw.GetDefineMethodHelper().DefineMethod(factory, tb, mw.Name, attr);
					if (mw.Name != mw.RealName)
					{
						tb.DefineMethodOverride(mb, (MethodInfo)mw.GetMethod());
					}
					CodeEmitter ilgen = CodeEmitter.Create(mb);
					for (int i = 0, count = mw.GetParameters().Length; i <= count; i++)
					{
						ilgen.EmitLdarg(i);
					}
					CoreClasses.java.lang.Object.Wrapper.GetMethodWrapper(mw.Name, mw.Signature, false).EmitCallvirt(ilgen);
					ilgen.Emit(OpCodes.Ret);
					ilgen.DoEmit();
				}
			}
		}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:34,代码来源:LambdaMetafactory.cs

示例3: EmitDispatch

		private static void EmitDispatch(DynamicTypeWrapper.FinishContext context, TypeWrapper[] args, TypeBuilder tb, MethodWrapper interfaceMethod, TypeWrapper[] implParameters,
			ClassFile.ConstantPoolItemMethodHandle implMethod, ClassFile.ConstantPoolItemMethodType instantiatedMethodType, FieldBuilder[] capturedFields)
		{
			MethodBuilder mb = interfaceMethod.GetDefineMethodHelper().DefineMethod(context.TypeWrapper, tb, interfaceMethod.Name, MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.NewSlot | MethodAttributes.Final);
			if (interfaceMethod.Name != interfaceMethod.RealName)
			{
				tb.DefineMethodOverride(mb, (MethodInfo)interfaceMethod.GetMethod());
			}
			CodeEmitter ilgen = CodeEmitter.Create(mb);
			for (int i = 0; i < capturedFields.Length; i++)
			{
				ilgen.EmitLdarg(0);
				OpCode opc = OpCodes.Ldfld;
				if (i == 0 && args[0].IsGhost)
				{
					switch (implMethod.Kind)
					{
						case ClassFile.RefKind.invokeInterface:
						case ClassFile.RefKind.invokeVirtual:
						case ClassFile.RefKind.invokeSpecial:
							opc = OpCodes.Ldflda;
							break;
					}
				}
				ilgen.Emit(opc, capturedFields[i]);
			}
			for (int i = 0, count = interfaceMethod.GetParameters().Length, k = capturedFields.Length; i < count; i++)
			{
				ilgen.EmitLdarg(i + 1);
				TypeWrapper Ui = interfaceMethod.GetParameters()[i];
				TypeWrapper Ti = instantiatedMethodType.GetArgTypes()[i];
				TypeWrapper Aj = implParameters[i + k];
				if (Ui == PrimitiveTypeWrapper.BYTE)
				{
					ilgen.Emit(OpCodes.Conv_I1);
				}
				if (Ti != Ui)
				{
					if (Ti.IsGhost)
					{
						Ti.EmitConvStackTypeToSignatureType(ilgen, Ui);
					}
					else if (Ui.IsGhost)
					{
						Ui.EmitConvSignatureTypeToStackType(ilgen);
					}
					else
					{
						Ti.EmitCheckcast(ilgen);
					}
				}
				if (Ti != Aj)
				{
					if (Ti.IsPrimitive && !Aj.IsPrimitive)
					{
						Boxer.EmitBox(ilgen, Ti);
					}
					else if (!Ti.IsPrimitive && Aj.IsPrimitive)
					{
						TypeWrapper primitive = GetPrimitiveFromWrapper(Ti);
						Boxer.EmitUnbox(ilgen, primitive, false);
						if (primitive == PrimitiveTypeWrapper.BYTE)
						{
							ilgen.Emit(OpCodes.Conv_I1);
						}
					}
					else if (Aj == PrimitiveTypeWrapper.LONG)
					{
						ilgen.Emit(OpCodes.Conv_I8);
					}
					else if (Aj == PrimitiveTypeWrapper.FLOAT)
					{
						ilgen.Emit(OpCodes.Conv_R4);
					}
					else if (Aj == PrimitiveTypeWrapper.DOUBLE)
					{
						ilgen.Emit(OpCodes.Conv_R8);
					}
				}
			}
			switch (implMethod.Kind)
			{
				case ClassFile.RefKind.invokeVirtual:
				case ClassFile.RefKind.invokeInterface:
					((MethodWrapper)implMethod.Member).EmitCallvirt(ilgen);
					break;
				case ClassFile.RefKind.newInvokeSpecial:
					((MethodWrapper)implMethod.Member).EmitNewobj(ilgen);
					break;
				case ClassFile.RefKind.invokeStatic:
				case ClassFile.RefKind.invokeSpecial:
					((MethodWrapper)implMethod.Member).EmitCall(ilgen);
					break;
				default:
					throw new InvalidOperationException();
			}
			TypeWrapper Ru = interfaceMethod.ReturnType;
			TypeWrapper Ra = GetImplReturnType(implMethod);
			TypeWrapper Rt = instantiatedMethodType.GetRetType();
			if (Ra == PrimitiveTypeWrapper.BYTE)
//.........这里部分代码省略.........
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:101,代码来源:LambdaMetafactory.cs

示例4: RemoveReadResolve

 private static void RemoveReadResolve(TypeBuilder tb)
 {
     tb.AddInterfaceImplementation(JVM.Import(typeof(IObjectReference)));
     MethodBuilder getRealObject = tb.DefineMethod("IObjectReference.GetRealObject", MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.NewSlot | MethodAttributes.Final,
         Types.Object, new Type[] { JVM.Import(typeof(StreamingContext)) });
     getRealObject.SetCustomAttribute(securityCriticalAttribute);
     AttributeHelper.HideFromJava(getRealObject);
     tb.DefineMethodOverride(getRealObject, JVM.Import(typeof(IObjectReference)).GetMethod("GetRealObject"));
     CodeEmitter ilgen = CodeEmitter.Create(getRealObject);
     ilgen.Emit(OpCodes.Ldarg_0);
     ilgen.Emit(OpCodes.Ret);
     ilgen.DoEmit();
 }
开发者ID:LogosBible,项目名称:ikvm-fork,代码行数:13,代码来源:Serialization.cs

示例5: AddReadResolve

 private static void AddReadResolve(DynamicTypeWrapper wrapper, TypeBuilder tb)
 {
     MethodWrapper mw = wrapper.GetMethodWrapper("readResolve", "()Ljava.lang.Object;", false);
     if (mw != null && !wrapper.IsSubTypeOf(iobjectreference))
     {
         tb.AddInterfaceImplementation(JVM.Import(typeof(IObjectReference)));
         MethodBuilder getRealObject = tb.DefineMethod("IObjectReference.GetRealObject", MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.NewSlot | MethodAttributes.Final,
             Types.Object, new Type[] { JVM.Import(typeof(StreamingContext)) });
         getRealObject.SetCustomAttribute(securityCriticalAttribute);
         AttributeHelper.HideFromJava(getRealObject);
         tb.DefineMethodOverride(getRealObject, JVM.Import(typeof(IObjectReference)).GetMethod("GetRealObject"));
         CodeEmitter ilgen = CodeEmitter.Create(getRealObject);
         mw.Link();
         if (!wrapper.IsFinal)
         {
             // readResolve is only applicable if it exists on the actual type of the object, so if we're a subclass don't call it
             ilgen.Emit(OpCodes.Ldarg_0);
             ilgen.Emit(OpCodes.Callvirt, Compiler.getTypeMethod);
             ilgen.Emit(OpCodes.Ldtoken, wrapper.TypeAsBaseType);
             ilgen.Emit(OpCodes.Call, Compiler.getTypeFromHandleMethod);
             CodeEmitterLabel label = ilgen.DefineLabel();
             ilgen.EmitBeq(label);
             ilgen.Emit(OpCodes.Ldarg_0);
             ilgen.Emit(OpCodes.Ret);
             ilgen.MarkLabel(label);
         }
         ilgen.Emit(OpCodes.Ldarg_0);
         mw.EmitCall(ilgen);
         ilgen.Emit(OpCodes.Ret);
         ilgen.DoEmit();
     }
 }
开发者ID:LogosBible,项目名称:ikvm-fork,代码行数:32,代码来源:Serialization.cs

示例6: AddGetObjectData

 private static void AddGetObjectData(TypeBuilder tb)
 {
     tb.AddInterfaceImplementation(JVM.Import(typeof(ISerializable)));
     MethodBuilder getObjectData = tb.DefineMethod("GetObjectData", MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.NewSlot, null,
         new Type[] { JVM.Import(typeof(SerializationInfo)), JVM.Import(typeof(StreamingContext)) });
     getObjectData.SetCustomAttribute(securityCriticalAttribute);
     AttributeHelper.HideFromJava(getObjectData);
     getObjectData.AddDeclarativeSecurity(SecurityAction.Demand, psetSerializationFormatter);
     tb.DefineMethodOverride(getObjectData, JVM.Import(typeof(ISerializable)).GetMethod("GetObjectData"));
     CodeEmitter ilgen = CodeEmitter.Create(getObjectData);
     ilgen.Emit(OpCodes.Ldarg_0);
     ilgen.Emit(OpCodes.Ldarg_1);
     TypeWrapper serializationHelper = ClassLoaderWrapper.LoadClassCritical("ikvm.internal.Serialization");
     MethodWrapper mw = serializationHelper.GetMethodWrapper("writeObject", "(Ljava.lang.Object;Lcli.System.Runtime.Serialization.SerializationInfo;)V", false);
     mw.Link();
     mw.EmitCall(ilgen);
     ilgen.Emit(OpCodes.Ret);
     ilgen.DoEmit();
 }
开发者ID:LogosBible,项目名称:ikvm-fork,代码行数:19,代码来源:Serialization.cs


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