public static class StatusExtensions {
static StatusExtensions() {
if ( Status.Good.IsBad() ) {
throw new InvalidOperationException( "Someone blinked." );
}
if ( Status.Failure.IsGood() ) {
throw new InvalidOperationException( "Someone blinked." );
}
if ( Status.Success.IsBad() ) {
throw new InvalidOperationException( "Someone blinked." );
}
if ( !Status.Unknown.IsUnknown() ) {
throw new InvalidOperationException( "Someone blinked." );
}
}
[Pure]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Boolean Failed( this Status status ) => status <= Status.Failure;
[Pure]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Boolean IsBad( this Status status ) => status.Failed();
[Pure]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Boolean IsUnknown( this Status status ) => status == Status.Unknown || !status.IsBad() && !status.IsGood();
[Pure]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Boolean Succeeded( this Status status ) => status >= Status.Success;
[Pure]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Boolean IsGood( this Status status ) => status.Succeeded();
[Pure]
[NotNull]
public static String Symbol( this Status status ) => status.GetDescription() ?? Symbols.Null;
[Pure]
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static Status ToStatus( this Boolean status ) => status ? Status.Success : Status.Failure;
}
Like this:
Like Loading...
Related
Published by Protiguous
C# Software Developer, SQL Server DBA, Father, and seeker of Truth.
View all posts by Protiguous