mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-12 11:15:12 +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>
|
||||
/// Gets the custom attributes added to the given assembly.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user