diff --git a/CryptoExchange.Net/CryptoExchange.Net.xml b/CryptoExchange.Net/CryptoExchange.Net.xml index da22b52..9e81788 100644 --- a/CryptoExchange.Net/CryptoExchange.Net.xml +++ b/CryptoExchange.Net/CryptoExchange.Net.xml @@ -1199,6 +1199,40 @@ + + + The result of an operation + + + + + An error if the call didn't succeed + + + + + Whether the call was successful + + + + + ctor + + + + + + Overwrite bool check so we can use if(callResult) instead of if(callResult.Success) + + + + + + Create an error result + + + + The result of an operation @@ -1210,16 +1244,6 @@ The data returned by the call - - - An error if the call didn't succeed - - - - - Whether the call was successful - - ctor @@ -1238,9 +1262,48 @@ Whether the call was successful or not. Useful for nullability checking. The data returned by the call. - on failure. + on failure. true when succeeded, false otherwise. + + + Create an error result + + + + + + + The result of a request + + + + + The status code of the response. Note that a OK status does not always indicate success, check the Success parameter for this. + + + + + The response headers + + + + + ctor + + + + + + + + Create an error result + + + + + + The result of a request @@ -1266,13 +1329,6 @@ - - - Create an error result - - - - Create an error result @@ -2994,7 +3050,9 @@ - + + +System.Diagnostics.CodeAnalysis.AllowNullAttribute"> Specifies that is allowed as an input even if the corresponding type disallows it. diff --git a/CryptoExchange.Net/Objects/CallResult.cs b/CryptoExchange.Net/Objects/CallResult.cs index a47e51a..f3be273 100644 --- a/CryptoExchange.Net/Objects/CallResult.cs +++ b/CryptoExchange.Net/Objects/CallResult.cs @@ -7,13 +7,8 @@ namespace CryptoExchange.Net.Objects /// /// The result of an operation /// - /// - public class CallResult + public class CallResult { - /// - /// The data returned by the call - /// - public T Data { get; internal set; } /// /// An error if the call didn't succeed /// @@ -23,15 +18,54 @@ namespace CryptoExchange.Net.Objects /// public bool Success => Error == null; + /// + /// ctor + /// + /// + public CallResult(Error? error) + { + Error = error; + } + + /// + /// Overwrite bool check so we can use if(callResult) instead of if(callResult.Success) + /// + /// + public static implicit operator bool(CallResult obj) + { + return obj?.Success == true; + } + + /// + /// Create an error result + /// + /// + /// + public static WebCallResult CreateErrorResult(Error error) + { + return new WebCallResult(null, null, error); + } + } + + /// + /// The result of an operation + /// + /// + public class CallResult: CallResult + { + /// + /// The data returned by the call + /// + public T Data { get; internal set; } + /// /// ctor /// /// /// - public CallResult([AllowNull]T data, Error? error) + public CallResult([AllowNull]T data, Error? error): base(error) { Data = data; - Error = error; } /// @@ -66,6 +100,58 @@ namespace CryptoExchange.Net.Objects return false; } } + + /// + /// Create an error result + /// + /// + /// + public new static WebCallResult CreateErrorResult(Error error) + { + return new WebCallResult(null, null, default, error); + } + } + + /// + /// The result of a request + /// + public class WebCallResult : CallResult + { + /// + /// The status code of the response. Note that a OK status does not always indicate success, check the Success parameter for this. + /// + public HttpStatusCode? ResponseStatusCode { get; set; } + + /// + /// The response headers + /// + public IEnumerable>>? ResponseHeaders { get; set; } + + /// + /// ctor + /// + /// + /// + /// + public WebCallResult( + HttpStatusCode? code, + IEnumerable>>? responseHeaders, Error? error) : base(error) + { + ResponseHeaders = responseHeaders; + ResponseStatusCode = code; + } + + /// + /// Create an error result + /// + /// + /// + /// + /// + public static WebCallResult CreateErrorResult(HttpStatusCode? code, IEnumerable>>? responseHeaders, Error error) + { + return new WebCallResult(code, responseHeaders, error); + } } /// @@ -83,7 +169,7 @@ namespace CryptoExchange.Net.Objects /// The response headers /// public IEnumerable>>? ResponseHeaders { get; set; } - + /// /// ctor /// @@ -95,18 +181,8 @@ namespace CryptoExchange.Net.Objects HttpStatusCode? code, IEnumerable>>? responseHeaders, [AllowNull] T data, Error? error): base(data, error) { - ResponseHeaders = responseHeaders; ResponseStatusCode = code; - } - - /// - /// Create an error result - /// - /// - /// - public static WebCallResult CreateErrorResult(Error error) - { - return new WebCallResult(null, null, default!, error); + ResponseHeaders = responseHeaders; } /// @@ -118,7 +194,7 @@ namespace CryptoExchange.Net.Objects /// public static WebCallResult CreateErrorResult(HttpStatusCode? code, IEnumerable>>? responseHeaders, Error error) { - return new WebCallResult(code, responseHeaders, default!, error); + return new WebCallResult(code, responseHeaders, default, error); } } }