예제 #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());
        }