I have a generic interface IFoo<>
, and a class Bar
that implements several interfaces such as IFoo<Class1>
, IFoo<Class2>
and IFoo<Class3>
. I can get the IFoo<ClassX>
type using:
Type foo = typeof(IFoo).MakeGenericType({typeOfOneOfTheClasses})
It's sure that a Bar
instance can be convert to foo type. I've tried Convert.ChangeType()
but failed.
How can I convert a object to one of its parent interfaces dynamically?
Aucun commentaire:
Enregistrer un commentaire