diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e71383..bc2dc41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + - Added extension method for getting type name without trailing generic info + ### Changed - Re-raise base exception from ReflectionUtils.CreateInstance, TargetInvocationException and TypeLoadException don't say much diff --git a/ICD.Common.Utils/Extensions/TypeExtensions.cs b/ICD.Common.Utils/Extensions/TypeExtensions.cs index 8264d6d..a67ac7d 100644 --- a/ICD.Common.Utils/Extensions/TypeExtensions.cs +++ b/ICD.Common.Utils/Extensions/TypeExtensions.cs @@ -283,5 +283,25 @@ namespace ICD.Common.Utils.Extensions return s_TypeMinimalInterfaces[extends]; } + + /// + /// Gets the Type name without any trailing generic information. + /// + /// E.g. + /// List`1 + /// Becomes + /// List + /// + /// + /// + public static string GetNameWithoutGenericArity(this Type extends) + { + if (extends == null) + throw new ArgumentNullException("extends"); + + string name = extends.Name; + int index = name.IndexOf('`'); + return index == -1 ? name : name.Substring(0, index); + } } }