public static TType Construct <TType>(Type derivedType) { if (typeof(TType).IsAssignableFrom(derivedType)) { return(TypeConstructionCache <TType> .Construct(derivedType)); } throw new ArgumentException($"Could not create instance of type `{derivedType.Name}` and convert to `{typeof(TType).Name}`: given type is not assignable to target type."); }
/// <summary> /// Constructs a new instance of the specified <see cref="TType"/>. /// </summary> /// <typeparam name="TType">The type we want to create a new instance of.</typeparam> /// <returns>A new instance of the <see cref="TType"/>.</returns> public static TType Construct <TType>() { return(TypeConstructionCache.Construct <TType>()); }
/// <summary> /// Constructs a new instance of the given type type and returns it as <see cref="TType"/>. /// </summary> /// <param name="derivedType">The type we want to create a new instance of.</param> /// <typeparam name="TType">The type we want to create a new instance of.</typeparam> /// <returns>a new instance of the <see cref="TType"/> type.</returns> /// <exception cref="ArgumentException">Thrown when the given type is not assignable to <see cref="TType"/></exception> public static TType Construct <TType>(Type derivedType) { return(TypeConstructionCache.Construct <TType>(derivedType)); }