using System; namespace MPF.Frontend { /// /// Generic success/failure result object, with optional message /// public class ResultEventArgs : EventArgs { /// /// Internal representation of success /// private readonly bool _success; /// /// Optional message for the result /// public string Message { get; } private ResultEventArgs(bool success, string message) { _success = success; Message = message; } /// /// Create a default success result with no message /// public static ResultEventArgs Success() => new(true, string.Empty); /// /// Create a success result with a custom message /// /// String to add as a message public static ResultEventArgs Success(string? message) => new(true, message ?? string.Empty); /// /// Create a default failure result with no message /// /// public static ResultEventArgs Failure() => new(false, string.Empty); /// /// Create a failure result with a custom message /// /// String to add as a message public static ResultEventArgs Failure(string? message) => new(false, message ?? string.Empty); /// /// Results can be compared to boolean values based on the success value /// public static implicit operator bool(ResultEventArgs result) => result._success; /// /// Results can be compared to boolean values based on the success value /// public static implicit operator ResultEventArgs(bool bval) => new(bval, string.Empty); } }