feat: Added extension method for getting type name without trailing generic info

This commit is contained in:
Chris Cameron
2018-07-06 14:58:16 -04:00
parent 21a583a57c
commit ae885974da
2 changed files with 23 additions and 0 deletions

View File

@@ -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

View File

@@ -283,5 +283,25 @@ namespace ICD.Common.Utils.Extensions
return s_TypeMinimalInterfaces[extends];
}
/// <summary>
/// Gets the Type name without any trailing generic information.
///
/// E.g.
/// List`1
/// Becomes
/// List
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
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);
}
}
}