5
내가 자동으로 모든 지역의 필드를 지 웁니다 인터페이스를 구현하려는
은, 지금까지 내가 가진 :유형의 기본값을 어떻게 내 보냅니 까?
// 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);
가 어떻게가 필드 위에 기본값을 저장하는 마지막 단계를 설정합니까? 같은
관심이 있습니까? http://stackoverflow.com/questions/10400358/how-to-translate-defaultsometype-from-c-sharp-to-cil –
그래 도움이됩니다. 사실, 나는 올바른 방법으로 Activator.CreateInstance (T)를 발생시킬 수 있다는 것을 알아 냈습니다. 이후 자동으로 기본 개체를 인스턴스화합니다. – sircodesalot
클래스 또는 구조체? 후자의 경우, 당신은'this = new StructName()'을 할 수 있습니다. – leppie