Under Standing Reflections

Understading reflection property
Reflection is the ability to find the information about types contained in an assembly at runtime. Reflection is the ability to find out information about objects, the application details (assemblies), its metadata at run-time.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Memory_understanding
{

    /// <summary>
    /// understanding the reflection property.
    /// </summary>
    class person
    {
        private int roll_number;
        private string name;

        public int Roll_number { get; set; }
        public string Name { get; set; }

        public void display()
        {
            Console.WriteLine("Student : " + Name + " Roll No " + Roll_number);

        }
        public void display2()
        {
            Console.WriteLine("This isto understand the reflection property");

        }

    }
    class program
    {
        public static void Main(string[] args)
        {
            person stu1 = new person();
            stu1.Roll_number = 34;
            stu1.Name = "Joseph";
            stu1.display();

            PropertyInfo[] properties = stu1.GetType().GetProperties();
            foreach (PropertyInfo pro in properties)
            {
                MethodInfo oMethodInfo = pro.GetType().GetMethod("get_" + pro.Name);
               // ParameterInfo[] Arry = pro.GetType().GetMethod("get_" + pro.Name).GetParameters();
                Console.WriteLine(pro.Name + "=" );
            }

            Type obj = stu1.GetType();
            MethodInfo mymethod = obj.GetMethod("display");
            MethodInfo mymethod2 = obj.GetMethod("display2");
            Console.WriteLine("FirstName " + obj.FullName);
            Console.WriteLine("First Method Name " + mymethod.Name);
            Console.WriteLine("Second Method Name " + mymethod2.Name);

            Console.ReadLine();
        }
    }

}

Comments

Popular posts from this blog

Authentication and Authorization in Web API -Part1

My Gardening Journey 6