using System; namespace Umbraco.ModelsBuilder.Embedded { internal static class TypeExtensions { /// /// Creates a generic instance of a generic type with the proper actual type of an object. /// /// A generic type such as Something{} /// An object whose type is used as generic type param. /// Arguments for the constructor. /// A generic instance of the generic type with the proper type. /// Usage... typeof (Something{}).CreateGenericInstance(object1, object2, object3) will return /// a Something{Type1} if object1.GetType() is Type1. public static object CreateGenericInstance(this Type genericType, object typeParmObj, params object[] ctorArgs) { var type = genericType.MakeGenericType(typeParmObj.GetType()); return Activator.CreateInstance(type, ctorArgs); } } }