我想实现一个自动清除所有本地字段的接口,到目前为止我有:
// Implement IClearable
dynamicType.AddInterfaceImplementation(typeof(IClearable));
MethodBuilder clearnMethodBuilder = dynamicType.DefineMethod("Clear", MethodAttributes.Public | MethodAttributes.Virtual, CallingConventions.Standard);
ILGenerator clearMethodILGen = clearnMethodBuilder.GetILGenerator();
foreach (FieldBuilder localField in fields)
{
clearMethodILGen.Emit(OpCodes.Ldarg_0);
clearMethodILGen.Emit(OpCodes.Ldfld, localField);
clearMethodILGen.Emit(OpCodes.??, Profit??);
}
clearMethodILGen.Emit(OpCodes.Ret);
如何设置最后一步以在字段上保存默认值?