Files

36 lines
879 B
C#
Executable File

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Opsoft.NetCore.O3App.Shared
{
public static class ByteExt
{
public static TOut ToEnum<TOut>( this byte value )
{
var outputType = typeof( TOut );
if ( outputType.IsEnum )
{
if ( outputType.IsEnumDefined( (int)value ) )
{
var obj = System.Enum.ToObject( outputType, value );
if ( obj != null )
{
return ( TOut )obj;
}
}
}
return default( TOut );
}
public static bool In(this byte source, params Enum[] enums)
{
return Array.Exists(enums, current => Convert.ToByte(current) == source);
}
}
}