feat: Added extension method for determining if a type is Anonymous

This commit is contained in:
Chris Cameron
2020-04-01 13:58:03 -04:00
parent b29ae4c8c8
commit 08aeba756a

View File

@@ -92,6 +92,20 @@ namespace ICD.Common.Utils.Extensions
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>
/// Returns true if the given type is a numeric type.
/// </summary>