本文整理汇总了C#中Mono.AddDefaultConstructor方法的典型用法代码示例。如果您正苦于以下问题:C# Mono.AddDefaultConstructor方法的具体用法?C# Mono.AddDefaultConstructor怎么用?C# Mono.AddDefaultConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono
的用法示例。
在下文中一共展示了Mono.AddDefaultConstructor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefineSerializationConstructor
private static void DefineSerializationConstructor(ModuleDefinition module, Mono.Cecil.TypeDefinition targetType)
{
var getTypeFromHandle = module.ImportMethod<Type>("GetTypeFromHandle", BindingFlags.Public | BindingFlags.Static);
Type[] parameterTypes = new Type[] { typeof(SerializationInfo), typeof(StreamingContext) };
// Define the constructor signature
var serializationCtor = targetType.AddDefaultConstructor();
serializationCtor.AddParameters(parameterTypes);
serializationCtor.Attributes = MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName | MethodAttributes.Public;
var interceptorInterfaceType = module.ImportType<IInterceptor>();
var interceptorTypeVariable = serializationCtor.AddLocal<Type>();
var body = serializationCtor.Body;
body.InitLocals = true;
var IL = serializationCtor.GetILGenerator();
IL.Emit(OpCodes.Ldtoken, interceptorInterfaceType);
IL.Emit(OpCodes.Call, getTypeFromHandle);
IL.Emit(OpCodes.Stloc, interceptorTypeVariable);
var defaultConstructor = module.ImportConstructor<object>();
IL.Emit(OpCodes.Ldarg_0);
IL.Emit(OpCodes.Call, defaultConstructor);
// __interceptor = (IInterceptor)info.GetValue("__interceptor", typeof(IInterceptor));
var getValue = module.ImportMethod<SerializationInfo>("GetValue");
IL.Emit(OpCodes.Ldarg_0);
IL.Emit(OpCodes.Ldarg_1);
IL.Emit(OpCodes.Ldstr, "__interceptor");
IL.Emit(OpCodes.Ldloc, interceptorTypeVariable);
IL.Emit(OpCodes.Callvirt, getValue);
IL.Emit(OpCodes.Castclass, interceptorInterfaceType);
var setInterceptor = module.ImportMethod<IProxy>("set_Interceptor");
IL.Emit(OpCodes.Callvirt, setInterceptor); ;
IL.Emit(OpCodes.Ret);
}