|
123456789101112131415161718192021222324252627282930313233343536 |
- using System;
- using System.Text;
- using Newtonsoft.Json;
- namespace Leadercraft.Server
- {
- internal class LeadercraftResult<T>
- {
- private string _responseJson;
-
- public readonly int StatusCode;
-
- public bool IsError { get => StatusCode < 200 || StatusCode > 299; }
-
- public ResultStruct<T> ParseResult()
- {
- return JsonConvert.DeserializeObject<ResultStruct<T>>(_responseJson);
- }
-
- public ResultStruct<string> ParseError()
- {
- return JsonConvert.DeserializeObject<ResultStruct<string>>(_responseJson);
- }
-
- public LeadercraftResult(string response, int status = 200)
- {
- this._responseJson = response;
- this.StatusCode = status;
- }
-
- public LeadercraftResult(byte[] response, int status = 200)
- {
- this._responseJson = Encoding.ASCII.GetString(response);
- this.StatusCode = status;
- }
- }
- }
|