Exemplo n.º 1
0
 /// <summary>
 /// Converts to the 64-bit signed integer.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="value"></param>
 /// <returns></returns>
 public static long ToInt64 <T>(this T value)
     where T : struct, Enum
 => FastEnum.GetUnderlyingType <T>() == typeof(long)
     ? Unsafe.As <T, long>(ref value)
 : throw new ArgumentException(nameof(value));
Exemplo n.º 2
0
 /// <summary>
 /// Converts to the 16-bit signed integer.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="value"></param>
 /// <returns></returns>
 public static short ToInt16 <T>(this T value)
     where T : struct, Enum
 => FastEnum.GetUnderlyingType <T>() == typeof(short)
     ? Unsafe.As <T, short>(ref value)
 : throw new ArgumentException(nameof(value));
Exemplo n.º 3
0
 /// <summary>
 /// Converts to the 32-bit unsigned integer.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="value"></param>
 /// <returns></returns>
 public static uint ToUInt32 <T>(this T value)
     where T : struct, Enum
 => FastEnum.GetUnderlyingType <T>() == typeof(uint)
     ? Unsafe.As <T, uint>(ref value)
 : throw new ArgumentException(nameof(value));
Exemplo n.º 4
0
 /// <summary>
 /// Converts to the 8-bit unsigned integer.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="value"></param>
 /// <returns></returns>
 public static byte ToByte <T>(this T value)
     where T : struct, Enum
 => FastEnum.GetUnderlyingType <T>() == typeof(byte)
     ? Unsafe.As <T, byte>(ref value)
 : throw new ArgumentException(nameof(value));