mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 12:07:05 +00:00
feat: Added extension method for getting type name without trailing generic info
This commit is contained in:
parent
21a583a57c
commit
ae885974da
2 changed files with 23 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue