dimanche 23 août 2015

Set a readoly/InitOnly member field using Linq Expressions

Given a FieldInfo, it is possible to set a C# readonly / CLR InitOnly member field.

When and Why would I want to do this? its for a serializer, I create an empty instance of the object type, and I then populate all the fields from the data stream.

To the actual question:

Is there a way to achieve this using Linq Expressions also? the Expression.Assign results in a exception if you pass an expression pointing to the readonly/initonly field.

Or will I have to resort to IL emit to do this (faster than FieldInfo)





Aucun commentaire:

Enregistrer un commentaire