Created
July 27, 2022 17:21
-
-
Save MessiDaGod/1d689c6c388d656bfcad836899ceb3de to your computer and use it in GitHub Desktop.
Is a field/type numeric C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static HashSet<Type> NumericTypes = new HashSet<Type> | |
{ | |
typeof(decimal), typeof(byte), typeof(sbyte), typeof(double) | |
,typeof(short), typeof(ushort), typeof(Single), typeof(UInt16) | |
,typeof(Int16), typeof(Int32), typeof(UInt32),typeof(UInt64) | |
,typeof(Int64), typeof(float) | |
}; | |
public static bool IsNumeric(Type type) | |
{ | |
return NumericTypes.Contains(type) || | |
NumericTypes.Contains(Nullable.GetUnderlyingType(type)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment