Skip to content

Instantly share code, notes, and snippets.

@vexx32
Created August 28, 2018 23:58
Show Gist options
  • Save vexx32/e61df1919f8eae9ef3156372ab18a50b to your computer and use it in GitHub Desktop.
Save vexx32/e61df1919f8eae9ef3156372ab18a50b to your computer and use it in GitHub Desktop.
// Generic this --> multiple type handling
internal static bool TryConvertSByte(double value, out sbyte outValue)
{
if (value < sbyte.MinValue || value > sbyte.MaxValue)
{
outValue = 0;
return false;
}
outValue = (sbyte)Math.Round(value);
return true;
}
internal static bool TryConvert<T>(double value, out T outValue) where T : struct
{
switch (T)
{
case Type T when T == sbyte:
// stuff
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment