jeudi 15 août 2019

Is there anyway for me to detect if member is copied by Value?

Consider the case where I'm making a deep copy of the complex class via as generic reflection method as possible. I collect all properties/fields, reflect on their type and if it is a ValueType or a Primitive I straight copy it because I dont need to care about reference case. The problem arises with our lovely string.

It returns both false to isPrimitive and isValueType, since it is not one of them, but also happily returns true to .isClass because of String. But I cant really run Activator to create instance of string so in the end I end up with beautiful piece like this:

map[i].PropertyType.IsValueType || map[i].PropertyType.IsPrimitive ||  map[i].PropertyType == typeof(string)





Aucun commentaire:

Enregistrer un commentaire