I am trying to dynamically create a proxy, so I am trying to use Emit. So when I set my field using emit, I also need to set the isDirty field boolan to true.
How can i do this?
Property Customer { set { this.customerName = value; this.isDirty = true; } }
emit code:
FieldBuilder isDirtyField = myTypeBuilder.DefineField("isDirty", typeof(bool), FieldAttributes.Private); // Define the "set" accessor method for CustomerName. MethodBuilder custNameSetPropMthdBldr = myTypeBuilder.DefineMethod("set_CustomerName", getSetAttr, null, new Type[] { typeof(string) }); ILGenerator custNameSetIL = custNameSetPropMthdBldr.GetILGenerator(); custNameSetIL.Emit(OpCodes.Ldarg_0); custNameSetIL.Emit(OpCodes.Ldarg_1); custNameSetIL.Emit(OpCodes.Stfld, customerNameBldr); { custNameSetIL.EmitWriteLine("Start isDirty"); ... do stuf here custNameSetIL.EmitWriteLine("End isDirty"); } custNameSetIL.Emit(OpCodes.Ret);
This code works, since for a long time I am not trying to make this isDirty field, after spending a weekend on this, I am trying to get some help on this forum. THX
// dennis
source share