I am trying to achieve this, no idea if it feasible though.. Here is a code sample:
public List<Tuple<AbstractPlateforme, AbstractPlateforme>> tuple;
Type type1 = tuple.Item1.GetType();
//This line gives me error: Error CS0118 'type1' is a variable but is used like a type
var plateforme = PlateformeHelper.GetPlateforme<type1>();
//This is my method from my PlateformeHelper class which returns an instance of an instantiated object of the same type (the list may only contain 1 object of that type which inherit from AbstractPlateforme)
public static T GetPlateforme<T>() where T : AbstractPlateforme
{
return (T)ListePlateforme.Find(x => x.GetType() == typeof (T));
}
Aucun commentaire:
Enregistrer un commentaire