dimanche 15 novembre 2015

Reflection to get value of a complex property in c#

I have the below class:-

public class TestClass : ITestClass
{

    IEnumerable<Type> IComponentRegistration.GetFirstItems
    {
        get
        {
            return new List<Type>
            {
                typeof (First),

            };
        }
    }

    IEnumerable<Type> IComponentRegistration.GetLastItems
    {
        get
        {
            return new List<Type>
            {
                typeof(Last)
            };
        }
    }
}

public interface ITestClass
{
    IEnumerable<System.Type> GetFirstItems { get; }
    IEnumerable<System.Type> GetLastItems { get; }
}

public class First
{
    public void Load(Customer cust)
    {
        Console.WriteLine(string.Format("My name from Session Component is {0} {1}",cust.FirstName,cust.LastName));
    }
}
public class Last
{
    public void Load(Customer cust)
    {
        Console.WriteLine(string.Format("My name from Validation Component is {0} {1}", cust.FirstName, cust.LastName));
    }
}

Now from the main method of a console application I need to Get value of GetFirstItems/GetLastItems and invoke the load method of Types returned.How can i do this using reflection?





Aucun commentaire:

Enregistrer un commentaire