mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
feat: Added extension method for determining if a type is Anonymous
This commit is contained in:
@@ -92,6 +92,20 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
return !extends.IsValueType || Nullable.GetUnderlyingType(extends) != null;
|
return !extends.IsValueType || Nullable.GetUnderlyingType(extends) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the type is anonymous.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool IsAnonymous([NotNull] this Type type)
|
||||||
|
{
|
||||||
|
if (type == null)
|
||||||
|
throw new ArgumentNullException("type");
|
||||||
|
|
||||||
|
return (type.Name.Contains("AnonymousType") || type.Name.Contains("AnonType")) &&
|
||||||
|
(type.Name.StartsWith("<>") || type.Name.StartsWith("VB$"));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns true if the given type is a numeric type.
|
/// Returns true if the given type is a numeric type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user