Using Reflection to set a Property with a type of List

HI friend

I use reflection to create a generic List with a custom class (List<CustomClass>).
use this Code,

class Properties
{
    public string ProData { get; set; }
}
class Program
{
    static void Main()
    {
     Type type = typeof(Properties); // possibly from a string
     IList list = (IList) Activator.CreateInstance(
            typeof(List<>).MakeGenericType(type));

        object obj = Activator.CreateInstance(type);
        type.GetProperty("ProData").SetValue(obj, "abc", null);
        list.Add(obj);
    }
}

0 comments: