mercredi 6 mai 2015

How do I determine Int32 is in fact assignable from Int16

I have a several PropertyInfo objects that represent properties of a target object. And a similar set of PropertyInfo objects that represent the properties of a source object.

My code assigns property values from source to target if the name and type matches. But some of the types are assignable but not exact match. One of the cases is source property of type Int16 but on target side the property of same name is of type Int32. I use the targetProperty.Type.IsAssignableFrom(sourceProperty.Type).

So in other words, the following is returning false while I really want it to give me a `true'

typeof(Int32).IsAssignableFrom(typeof(Int16))

I have read other threads which suggest me that IsAssignableFrom is not what I need. Before I jump on to write a long switch-case code, I am checking to see if there is any easier way.





Aucun commentaire:

Enregistrer un commentaire