From 3097ff76959a58260799bbb39c2732f36a979132 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 12 Feb 2025 10:46:14 +0100 Subject: [PATCH] Update x nuova vers unstable --- EgwProxy.Shelly/ShellyResult.cs | 84 ++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 34 deletions(-) diff --git a/EgwProxy.Shelly/ShellyResult.cs b/EgwProxy.Shelly/ShellyResult.cs index 91c543f..32f81c9 100644 --- a/EgwProxy.Shelly/ShellyResult.cs +++ b/EgwProxy.Shelly/ShellyResult.cs @@ -8,18 +8,12 @@ namespace EgwProxy.Shelly { public class ShellyResult { - public T Value - { - get - { - if (!_successChecked) - { - throw new InvalidOperationException("Cannot access value of result without checking success first"); - } + #region Public Properties - return _value; - } - } + /// + /// Indicates the client request has failed + /// + public bool IsFailure => !IsSuccess; /// /// Indicates the client request has completed successfully @@ -34,12 +28,7 @@ namespace EgwProxy.Shelly } /// - /// Indicates the client request has failed - /// - public bool IsFailure => !IsSuccess; - - /// - /// Indicates if the reason for failure is transient + /// Indicates if the reason for failure is transient /// public bool IsTransient { get; private set; } @@ -48,9 +37,49 @@ namespace EgwProxy.Shelly /// 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 Failure(string message = null) + { + return new ShellyResult(default, success: false, isTransient: false, message); + } + + public static ShellyResult Success(T value, string message = null) + { + return new ShellyResult(value, true, false, message); + } + + public static ShellyResult TransientFailure(string message = null) + { + return new ShellyResult(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 Success(T value, string message = null) - { - return new ShellyResult(value, true, false, message); - } - - public static ShellyResult Failure(string message = null) - { - return new ShellyResult(default, success: false, isTransient: false, message); - } - - public static ShellyResult TransientFailure(string message = null) - { - return new ShellyResult(default, success: false, isTransient: true, message); - } + #endregion Private Constructors } -} +} \ No newline at end of file