Is there a way to set C# readonly auto-implemented Propeties through reflection? -
the title says all: there way set c# readonly auto-implemented propeties through reflection?
typeof(change) .getproperty("changetype", bindingflags.instance | bindingflags.public) .setvalue(mychange, change.changetype.transform(),null);
this line gives me error : system.argumentexception - {"property set method not found."}. thing can't use getfield because there no fields.
before ask, i'm doing because need "complement" finished library , have no access code.
this should work, there not telling us. sure it's auto-implemented property? explanation consistent seeing property not auto-implemented , not have setter.
that is,
public class foo { public int bar { get; set; } } typeof(foo).getproperty("bar").setvalue(foo, 42);
will succeed but
public class foo { public int bar { { return 42; } } } typeof(foo).getproperty("bar").setvalue(foo, 42);
will not , produce exception message seeing.
Comments
Post a Comment