mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-18 06:05:00 +00:00
feat: Added extension method for getting type name without trailing generic info
This commit is contained in:
@@ -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).
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Added
|
||||||
|
- Added extension method for getting type name without trailing generic info
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Re-raise base exception from ReflectionUtils.CreateInstance, TargetInvocationException and TypeLoadException don't say much
|
- 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];
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user