Following example might help you, I assume you would like to
create object of a type based on some creation criteria at Runtime using REflection
namespace RuntimeObjectCreation
{
using System;
using System.Collections.Generic;
class Program
{
public static IDictionary<string, string> Selector = new Dictionary<string, string>()
{
{"A","RuntimeObjectCreation.ClassA"},
{"B","RuntimeObjectCreation.ClassB"},
{"C","RuntimeObjectCreation.ClassC"}
};
static void Main(string[] args)
{
SelectionClass sc = new SelectionClass();
var @object = sc.GetSelectedObject(Selector["A"]);
}
}
public class SelectionClass
{
public object GetSelectedObject(string typeName)
{
return Activator.CreateInstance(null, typeName);
}
}
public class ClassA
{
public string AName { get; set; }
}
public class ClassB
{
public string BName { get; set; }
}
public class ClassC
{
public string CName { get; set; }
}
}
Hope it helps :)