Пример #1
0
        private static Type GetDogType()
        {
            var dog  = new Dog();
            var type = dog.GetType();

            return(type);
        }
Пример #2
0
        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();
        }
Пример #3
0
        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());
        }