Join GitHub today
Support readonly fields #6202
Note that this issue is talking about readonly fields, not properties. That is, fields that are decalred as
The only way to set the field that works is using Reflection with FieldInfo.SetValue. We can compile this method call into the expression tree (only doing so if "initonly" flag is set). Since the FieldInfo is cached performance is not horrendous, but it is a lot worse than just compiling an assign--approximately 100 times slower.
So the question is should we use Reflection for this, or should we throw saying not to use readonly fields or read only auto-properties?
Keep in mind that we will support these types of fields in some scenarios when we support materialization through parameterized constructors. This would be ideal for normal materialization, but it won't support things like key propagation or fixup.