mardi 19 décembre 2017

How to copy from List to list using reflection? C#

Both object are "the same" but its imposible for me, to copy de object definition directly.

The class A looks like:

public class A { 
    [JsonProperty(PropertyName="MyPROP")]
    List<Namespace.Property> pro {get; set;}
}

The class B looks like:

public class B { 
    [JsonProperty(PropertyName="MyNewPropertyName")]
    List<MyNames.Property> pro {get; set;}
}

As you can see, the only differences are attributes and namespace, both classes has the same methods and properties.

The error I'm getting using reflection is this

El objeto de tipo 'System.Collections.Generic.List1[Namespace.Property]' no puede convertirse en el tipo 'System.Collections.Generic.List1[MyNames.Property]'.





Aucun commentaire:

Enregistrer un commentaire