c# - Set auto-property's value via reflection -


i've seen various threads on how call property's private setter via reflection. however, auto-properties without setter?

public class test {     public string property { get; } = ""; } 

is possible set value of readonly property using reflection?

  • propertyinfo.setmethod returns null
  • propertyinfo.setvalue fails

any ideas?

is possible set value of readonly property using reflection?

no. properties backed read-only fields. there is no setter; assignments performed in constructor write directly fields.

if design makes want write read-only property via reflection, should revisit design :)


Comments