jeudi 3 août 2017

How does a DataContractSerializer deserialize readonly fields?

A DataContractSerializer will happily deserialize this class, including the readonly field:

[DataContract]
public class A
{
    public A(int rof) => Rof = rof;

    [DataMember]
    private readonly int Rof;
}

How does it do that? It has a reputation for being fast so I assume it doesn't use FieldInfo.SetValue(), does it?

Expression.Assign() doesn't seem to work, nor does emitting Stfld.





Aucun commentaire:

Enregistrer un commentaire