Update x nuova vers unstable
This commit is contained in:
@@ -8,18 +8,12 @@ namespace EgwProxy.Shelly
|
||||
{
|
||||
public class ShellyResult<T>
|
||||
{
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_successChecked)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot access value of result without checking success first");
|
||||
}
|
||||
#region Public Properties
|
||||
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Indicates the client request has failed
|
||||
/// </summary>
|
||||
public bool IsFailure => !IsSuccess;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the client request has completed successfully
|
||||
@@ -34,12 +28,7 @@ namespace EgwProxy.Shelly
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the client request has failed
|
||||
/// </summary>
|
||||
public bool IsFailure => !IsSuccess;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the reason for failure is transient
|
||||
/// Indicates if the reason for failure is transient
|
||||
/// </summary>
|
||||
public bool IsTransient { get; private set; }
|
||||
|
||||
@@ -48,9 +37,49 @@ namespace EgwProxy.Shelly
|
||||
/// </summary>
|
||||
public string Message { get; }
|
||||
|
||||
private T _value;
|
||||
private bool _successChecked = false;
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_successChecked)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot access value of result without checking success first");
|
||||
}
|
||||
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public static ShellyResult<T> Failure(string message = null)
|
||||
{
|
||||
return new ShellyResult<T>(default, success: false, isTransient: false, message);
|
||||
}
|
||||
|
||||
public static ShellyResult<T> Success(T value, string message = null)
|
||||
{
|
||||
return new ShellyResult<T>(value, true, false, message);
|
||||
}
|
||||
|
||||
public static ShellyResult<T> TransientFailure(string message = null)
|
||||
{
|
||||
return new ShellyResult<T>(default, success: false, isTransient: true, message);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private bool _success = false;
|
||||
private bool _successChecked = false;
|
||||
private T _value;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Constructors
|
||||
|
||||
private ShellyResult(T value, bool success, bool isTransient, string message = null)
|
||||
{
|
||||
@@ -60,19 +89,6 @@ namespace EgwProxy.Shelly
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public static ShellyResult<T> Success(T value, string message = null)
|
||||
{
|
||||
return new ShellyResult<T>(value, true, false, message);
|
||||
}
|
||||
|
||||
public static ShellyResult<T> Failure(string message = null)
|
||||
{
|
||||
return new ShellyResult<T>(default, success: false, isTransient: false, message);
|
||||
}
|
||||
|
||||
public static ShellyResult<T> TransientFailure(string message = null)
|
||||
{
|
||||
return new ShellyResult<T>(default, success: false, isTransient: true, message);
|
||||
}
|
||||
#endregion Private Constructors
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user