using System; using System.Linq; using System.Reflection; namespace sharp.extensions { public class ConstructableObject { public string AssemblyName; public string TypeName; public object[] ConstructorArguments; public ConstructableObject(){ } public ConstructableObject(object o) { Type t = o.GetType(); TypeName = t.FullName; AssemblyName = t.Assembly.FullName; if (t.GetInterfaces().Contains(typeof(IConstructorArguments))){ this.ConstructorArguments = ((IConstructorArguments)o).getConstructorArguments(); } else { this.ConstructorArguments = new object[0]; } } public object Construct(){ Assembly assy = Assembly.Load(AssemblyName); Type t = assy.GetType(TypeName); object o = Activator.CreateInstance(t, ConstructorArguments); return o; } } }