Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RetryConditionHeaderValue.cs
Go to the documentation of this file.
3
5
7{
8 private readonly DateTimeOffset? _date;
9
10 private readonly TimeSpan? _delta;
11
13
14 public TimeSpan? Delta => _delta;
15
17 {
18 _date = date;
19 }
20
22 {
23 if (delta.TotalSeconds > 2147483647.0)
24 {
25 throw new ArgumentOutOfRangeException("delta");
26 }
27 _delta = delta;
28 }
29
35
36 public override string ToString()
37 {
38 if (_delta.HasValue)
39 {
40 return ((int)_delta.Value.TotalSeconds).ToString(NumberFormatInfo.InvariantInfo);
41 }
42 return HttpDateParser.DateToString(_date.Value);
43 }
44
45 public override bool Equals([NotNullWhen(true)] object? obj)
46 {
47 if (!(obj is RetryConditionHeaderValue retryConditionHeaderValue))
48 {
49 return false;
50 }
51 if (_delta.HasValue)
52 {
53 if (retryConditionHeaderValue._delta.HasValue)
54 {
55 return _delta.Value == retryConditionHeaderValue._delta.Value;
56 }
57 return false;
58 }
59 if (retryConditionHeaderValue._date.HasValue)
60 {
61 return _date.Value == retryConditionHeaderValue._date.Value;
62 }
63 return false;
64 }
65
66 public override int GetHashCode()
67 {
68 if (!_delta.HasValue)
69 {
70 return _date.Value.GetHashCode();
71 }
72 return _delta.Value.GetHashCode();
73 }
74
75 public static RetryConditionHeaderValue Parse(string? input)
76 {
77 int index = 0;
79 }
80
81 public static bool TryParse([NotNullWhen(true)] string? input, [NotNullWhen(true)] out RetryConditionHeaderValue? parsedValue)
82 {
83 int index = 0;
84 parsedValue = null;
85 if (GenericHeaderParser.RetryConditionParser.TryParseValue(input, null, ref index, out var parsedValue2))
86 {
87 parsedValue = (RetryConditionHeaderValue)parsedValue2;
88 return true;
89 }
90 return false;
91 }
92
93 internal static int GetRetryConditionLength(string input, int startIndex, out object parsedValue)
94 {
95 parsedValue = null;
96 if (string.IsNullOrEmpty(input) || startIndex >= input.Length)
97 {
98 return 0;
99 }
100 int num = startIndex;
102 int result2 = -1;
103 char c = input[num];
104 if (c >= '0' && c <= '9')
105 {
106 int offset = num;
107 int numberLength = HttpRuleParser.GetNumberLength(input, num, allowDecimal: false);
108 if (numberLength == 0 || numberLength > 10)
109 {
110 return 0;
111 }
112 num += numberLength;
114 if (num != input.Length)
115 {
116 return 0;
117 }
118 if (!HeaderUtilities.TryParseInt32(input, offset, numberLength, out result2))
119 {
120 return 0;
121 }
122 }
123 else
124 {
125 if (!HttpDateParser.TryParse(input.AsSpan(num), out result))
126 {
127 return 0;
128 }
129 num = input.Length;
130 }
131 if (result2 == -1)
132 {
133 parsedValue = new RetryConditionHeaderValue(result);
134 }
135 else
136 {
137 parsedValue = new RetryConditionHeaderValue(new TimeSpan(0, 0, result2));
138 }
139 return num - startIndex;
140 }
141
143 {
144 return new RetryConditionHeaderValue(this);
145 }
146}
static string DateToString(DateTimeOffset dateTime)
static bool TryParse(ReadOnlySpan< char > input, out DateTimeOffset result)
static readonly GenericHeaderParser RetryConditionParser
static bool TryParseInt32(string value, out int result)
static RetryConditionHeaderValue Parse(string? input)
static int GetRetryConditionLength(string input, int startIndex, out object parsedValue)
override bool Equals([NotNullWhen(true)] object? obj)
static bool TryParse([NotNullWhen(true)] string? input, [NotNullWhen(true)] out RetryConditionHeaderValue? parsedValue)
static int GetWhitespaceLength(string input, int startIndex)
static int GetNumberLength(string input, int startIndex, bool allowDecimal)
override int GetHashCode()
static readonly DateTimeOffset MinValue
double TotalSeconds
Definition TimeSpan.cs:64
override int GetHashCode()
Definition TimeSpan.cs:195