AfficherConstructeurs(3.14159f);
AfficherType("J'aime mon prof");
AfficherConstructeurs("J'aime mon prof");
AfficherMéthodes("J'aime mon prof");
Console.WriteLine(InvoquerDernierConstructeur
"J'aime mon prof", new object[] { 'Z', 3 }
static void AfficherType<T>(T obj)
Type type = obj.GetType();
Console.WriteLine($"Type de {obj}: {type}");
static void AfficherConstructeurs<T>(T obj)
Type type = obj.GetType();
ConstructorInfo[] ctorInf = type.GetConstructors();
foreach (ConstructorInfo ci in ctorInf)
Console.WriteLine($"{type} a comme constructeur {ci}");
static void AfficherMéthodes<T>(T obj)
Type type = obj.GetType();
MethodInfo[] methInf = type.GetMethods();
foreach (MethodInfo mi in methInf)
Console.WriteLine($"{type} a comme méthode {mi}");
static T InvoquerDernierConstructeur<T>(T obj, object[] paramètres)
int nCtors = obj.GetType().GetConstructors().Length;
return (T)obj.GetType().GetConstructors()[nCtors - 1].Invoke(paramètres);