mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-12 19:25:00 +00:00
feat: Added extension method for getting type name without trailing generic info
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user