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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -