mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
Shim to instantiate a known type
This commit is contained in:
@@ -260,6 +260,21 @@ namespace ICD.Common.Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates an instance of the given type, calling the default constructor.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static T CreateInstance<T>(Type type)
|
||||||
|
{
|
||||||
|
if (type == null)
|
||||||
|
throw new ArgumentNullException("type");
|
||||||
|
|
||||||
|
if (!type.IsAssignableTo(typeof(T)))
|
||||||
|
throw new InvalidOperationException("Type is not assignable to T");
|
||||||
|
|
||||||
|
return (T)CreateInstance(type);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the custom attributes added to the given assembly.
|
/// Gets the custom attributes added to the given assembly.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user