Skip to content

Instantly share code, notes, and snippets.

@KirillOsenkov
Created May 25, 2022 16:16
Show Gist options
  • Save KirillOsenkov/f982fcb5f506eedc4342494eebb6e526 to your computer and use it in GitHub Desktop.
Save KirillOsenkov/f982fcb5f506eedc4342494eebb6e526 to your computer and use it in GitHub Desktop.
bool CanConvertToHex(object value)
{
return value switch
{
byte or sbyte or ushort or short or uint or int or ulong or long or IntPtr or UIntPtr => true,
_ => false
};
}
@thomaslevesque
Copy link

bool CanConvertToHex(object value) => value is byte or sbyte or ushort or short or uint or int or ulong or long or IntPtr or UIntPtr;

@KirillOsenkov
Copy link
Author

Nice! Why did I not think of this

@teo-tsirpanis
Copy link

teo-tsirpanis commented May 25, 2022

or IntPtr or UIntPtr

or nint or nuint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment