mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-14 04:58:33 +00:00
Shim to instantiate a known type
This commit is contained in:
parent
e07bffaf90
commit
cd4791538a
1 changed files with 15 additions and 0 deletions
|
|
@ -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>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue