I have a variable of List<Tbase>
. I know that all items in it are of TChild
. I have this TChild
type only as a variable similar to var t = typeof(TChild)
.
So I tried:
var elementType = param.ParameterType.GenericTypeArguments.First();
var values = value.Select(x => Dynamic.InvokeConvert(x, elementType, true)).ToList();
Yet It gives type 'System.Collections.Generic.List1[System.Object]'
white I need it to be of target type.
So how to cast a List<TBase>
to a List<TChild>
using reflection (not using Linq Cast<>
)?
Aucun commentaire:
Enregistrer un commentaire