I want to to cast a list of object type A to a list of object type B, where A inherit B.
Concretely :
public class A : B
{
public string name { get; set; }
}
public class B
{
public B() { }
}
I parse a JSON string that I cast to my list of type A :
B elem = ((JArray)_configuration).ToObject<List<A>>();
And I have this error :
Cannot implicitly convert type 'System.Collections.Generic.List< A>' to 'System.Collections.Generic.List< B>'
I tried to cast it :
List<B> elem = (List<B>)((JArray)_configuration).ToObject<List<A>>();
but got this error :
Cannot convert type 'System.Collections.Generic.List< A>' to 'System.Collections.Generic.List< B>'
I couldn't find help, maybe because I don't know what to look for, so apologies if it has been answered somewhere already !