From cd4791538a0928d690684bf7e8df3916926c9897 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Mon, 19 Feb 2018 15:23:08 -0500 Subject: [PATCH] Shim to instantiate a known type --- ICD.Common.Utils/ReflectionUtils.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ICD.Common.Utils/ReflectionUtils.cs b/ICD.Common.Utils/ReflectionUtils.cs index 2cd7c36..76b182b 100644 --- a/ICD.Common.Utils/ReflectionUtils.cs +++ b/ICD.Common.Utils/ReflectionUtils.cs @@ -260,6 +260,21 @@ namespace ICD.Common.Utils } } + /// + /// Creates an instance of the given type, calling the default constructor. + /// + /// + public static T CreateInstance(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); + } + /// /// Gets the custom attributes added to the given assembly. ///