0
설정 나는 그것을 속성을 방출하고 설정 하시겠습니까?방출 및 속성
설정 나는 그것을 속성을 방출하고 설정 하시겠습니까?방출 및 속성
the documentation for DefineProperty
을 보면 여전히 setter (및 getter) 메서드를 직접 정의해야합니다. 이 부분은 set
방법과 관련,하지만 당신은 아마 너무 get
방법을 수행해야합니다 :
// Backing field
FieldBuilder customerNameBldr = myTypeBuilder.DefineField(
"customerName",
typeof(string),
FieldAttributes.Private);
// Property
PropertyBuilder custNamePropBldr = myTypeBuilder.DefineProperty(
"CustomerName",
PropertyAttributes.HasDefault,
typeof(string),
null);
// Attributes for the set method.
MethodAttributes getSetAttr = MethodAttributes.Public |
MethodAttributes.SpecialName |
MethodAttributes.HideBySig;
// Set method
MethodBuilder custNameSetPropMthdBldr = myTypeBuilder.DefineMethod(
"set_CustomerName",
getSetAttr,
null,
new Type[] { typeof(string) });
ILGenerator custNameSetIL = custNameSetPropMthdBldr.GetILGenerator();
// Content of the set method
custNameSetIL.Emit(OpCodes.Ldarg_0);
custNameSetIL.Emit(OpCodes.Ldarg_1);
custNameSetIL.Emit(OpCodes.Stfld, customerNameBldr);
custNameSetIL.Emit(OpCodes.Ret);
// Apply the set method to the property.
custNamePropBldr.SetSetMethod(custNameSetPropMthdBldr);
유는 GET 방법 위원장 코드를 추가 할 수 있을까요? 나는 'br.s IL_0009'전화와 혼동을 느낀다 ... – Jaster
@Jaster 내가 준 링크에있다. – Rawling