private static Type GetDogType() { var dog = new Dog(); var type = dog.GetType(); return(type); }
private static void GetInfoFromAnimals() { Animal a = new Animal(); Animal d = new Dog(); Animal c = new Cat(); Console.WriteLine("Type for a is {0}", a.GetType().Name); Console.WriteLine("Type for d is {0}", d.GetType().Name); Console.WriteLine("Type for c is {0}", c.GetType().Name); Console.WriteLine(); }
private static void InvokeMethodByReflection() { Dog dog = GetDogInstance(); Console.WriteLine(dog.ToString()); var type = dog.GetType(); var methodInfo = type.GetMethod("set_Name"); methodInfo?.Invoke(dog, new object[] { "Thod Modified" }); Console.WriteLine(dog.ToString()); }