Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Boolean.cs
Go to the documentation of this file.
4
5namespace System;
6
8[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
9public readonly struct Boolean : IComparable, IConvertible, IComparable<bool>, IEquatable<bool>
10{
11 private readonly bool m_value;
12
13 public static readonly string TrueString = "True";
14
15 public static readonly string FalseString = "False";
16
17 public override int GetHashCode()
18 {
19 if (!this)
20 {
21 return 0;
22 }
23 return 1;
24 }
25
26 public override string ToString()
27 {
28 if (!this)
29 {
30 return "False";
31 }
32 return "True";
33 }
34
35 public string ToString(IFormatProvider? provider)
36 {
37 return ToString();
38 }
39
40 public bool TryFormat(Span<char> destination, out int charsWritten)
41 {
42 if (this)
43 {
44 if ((uint)destination.Length > 3u)
45 {
46 destination[0] = 'T';
47 destination[1] = 'r';
48 destination[2] = 'u';
49 destination[3] = 'e';
50 charsWritten = 4;
51 return true;
52 }
53 }
54 else if ((uint)destination.Length > 4u)
55 {
56 destination[0] = 'F';
57 destination[1] = 'a';
58 destination[2] = 'l';
59 destination[3] = 's';
60 destination[4] = 'e';
61 charsWritten = 5;
62 return true;
63 }
64 charsWritten = 0;
65 return false;
66 }
67
68 public override bool Equals([NotNullWhen(true)] object? obj)
69 {
70 if (!(obj is bool))
71 {
72 return false;
73 }
74 return this == (bool)obj;
75 }
76
77 [NonVersionable]
78 public bool Equals(bool obj)
79 {
80 return this == obj;
81 }
82
83 public int CompareTo(object? obj)
84 {
85 if (obj == null)
86 {
87 return 1;
88 }
89 if (!(obj is bool))
90 {
92 }
93 if (this == (bool)obj)
94 {
95 return 0;
96 }
97 if (!this)
98 {
99 return -1;
100 }
101 return 1;
102 }
103
104 public int CompareTo(bool value)
105 {
106 if (this == value)
107 {
108 return 0;
109 }
110 if (!this)
111 {
112 return -1;
113 }
114 return 1;
115 }
116
118 {
119 if (value.Length == 4 && (value[0] == 't' || value[0] == 'T') && (value[1] == 'r' || value[1] == 'R') && (value[2] == 'u' || value[2] == 'U'))
120 {
121 if (value[3] != 'e')
122 {
123 return value[3] == 'E';
124 }
125 return true;
126 }
127 return false;
128 }
129
131 {
132 if (value.Length == 5 && (value[0] == 'f' || value[0] == 'F') && (value[1] == 'a' || value[1] == 'A') && (value[2] == 'l' || value[2] == 'L') && (value[3] == 's' || value[3] == 'S'))
133 {
134 if (value[4] != 'e')
135 {
136 return value[4] == 'E';
137 }
138 return true;
139 }
140 return false;
141 }
142
143 public static bool Parse(string value)
144 {
145 if (value == null)
146 {
147 throw new ArgumentNullException("value");
148 }
149 return Parse(value.AsSpan());
150 }
151
152 public static bool Parse(ReadOnlySpan<char> value)
153 {
154 if (!TryParse(value, out var result))
155 {
156 throw new FormatException(SR.Format(SR.Format_BadBoolean, new string(value)));
157 }
158 return result;
159 }
160
161 public static bool TryParse([NotNullWhen(true)] string? value, out bool result)
162 {
163 if (value == null)
164 {
165 result = false;
166 return false;
167 }
168 return TryParse(value.AsSpan(), out result);
169 }
170
171 public static bool TryParse(ReadOnlySpan<char> value, out bool result)
172 {
174 {
175 result = true;
176 return true;
177 }
179 {
180 result = false;
181 return true;
182 }
185 {
186 result = true;
187 return true;
188 }
190 {
191 result = false;
192 return true;
193 }
194 result = false;
195 return false;
196 }
197
199 {
200 int i;
201 for (i = 0; i < value.Length && (char.IsWhiteSpace(value[i]) || value[i] == '\0'); i++)
202 {
203 }
204 int num = value.Length - 1;
205 while (num >= i && (char.IsWhiteSpace(value[num]) || value[num] == '\0'))
206 {
207 num--;
208 }
209 return value.Slice(i, num - i + 1);
210 }
211
213 {
214 return TypeCode.Boolean;
215 }
216
218 {
219 return this;
220 }
221
223 {
224 throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Boolean", "Char"));
225 }
226
228 {
229 return Convert.ToSByte(this);
230 }
231
233 {
234 return Convert.ToByte(this);
235 }
236
238 {
239 return Convert.ToInt16(this);
240 }
241
243 {
244 return Convert.ToUInt16(this);
245 }
246
248 {
249 return Convert.ToInt32(this);
250 }
251
253 {
254 return Convert.ToUInt32(this);
255 }
256
258 {
259 return Convert.ToInt64(this);
260 }
261
263 {
264 return Convert.ToUInt64(this);
265 }
266
268 {
269 return Convert.ToSingle(this);
270 }
271
273 {
274 return Convert.ToDouble(this);
275 }
276
278 {
279 return Convert.ToDecimal(this);
280 }
281
283 {
284 throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Boolean", "DateTime"));
285 }
286
288 {
289 return Convert.DefaultToType(this, type, provider);
290 }
291}
static decimal ToDecimal(object? value)
Definition Convert.cs:2101
static long ToInt64(object? value)
Definition Convert.cs:1623
static float ToSingle(object? value)
Definition Convert.cs:1881
static int ToInt32(object? value)
Definition Convert.cs:1320
static short ToInt16(object? value)
Definition Convert.cs:1038
static byte ToByte(object? value)
Definition Convert.cs:900
static uint ToUInt32(object? value)
Definition Convert.cs:1470
static ulong ToUInt64(object? value)
Definition Convert.cs:1738
static ushort ToUInt16(object? value)
Definition Convert.cs:1177
static sbyte ToSByte(object? value)
Definition Convert.cs:745
static double ToDouble(object? value)
Definition Convert.cs:1991
static object DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
Definition Convert.cs:269
static string InvalidCast_FromTo
Definition SR.cs:1392
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Arg_MustBeBoolean
Definition SR.cs:252
static string Format_BadBoolean
Definition SR.cs:1322
Definition SR.cs:7
short ToInt16(IFormatProvider? provider)
char ToChar(IFormatProvider? provider)
byte ToByte(IFormatProvider? provider)
decimal ToDecimal(IFormatProvider? provider)
object ToType(Type conversionType, IFormatProvider? provider)
uint ToUInt32(IFormatProvider? provider)
DateTime ToDateTime(IFormatProvider? provider)
int ToInt32(IFormatProvider? provider)
long ToInt64(IFormatProvider? provider)
ushort ToUInt16(IFormatProvider? provider)
double ToDouble(IFormatProvider? provider)
float ToSingle(IFormatProvider? provider)
sbyte ToSByte(IFormatProvider? provider)
ulong ToUInt64(IFormatProvider? provider)
bool ToBoolean(IFormatProvider? provider)
TypeCode
Definition TypeCode.cs:4
static ReadOnlySpan< char > TrimWhiteSpaceAndNull(ReadOnlySpan< char > value)
Definition Boolean.cs:198
static readonly string FalseString
Definition Boolean.cs:15
string ToString(IFormatProvider? provider)
Definition Boolean.cs:35
override int GetHashCode()
Definition Boolean.cs:17
override bool Equals([NotNullWhen(true)] object? obj)
Definition Boolean.cs:68
bool Equals(bool obj)
Definition Boolean.cs:78
static bool IsFalseStringIgnoreCase(ReadOnlySpan< char > value)
Definition Boolean.cs:130
override string ToString()
Definition Boolean.cs:26
int CompareTo(object? obj)
Definition Boolean.cs:83
bool TryFormat(Span< char > destination, out int charsWritten)
Definition Boolean.cs:40
static bool IsTrueStringIgnoreCase(ReadOnlySpan< char > value)
Definition Boolean.cs:117
static bool TryParse(ReadOnlySpan< char > value, out bool result)
Definition Boolean.cs:171
TypeCode GetTypeCode()
Definition Boolean.cs:212
static bool Parse(string value)
Definition Boolean.cs:143
static bool Parse(ReadOnlySpan< char > value)
Definition Boolean.cs:152
static readonly string TrueString
Definition Boolean.cs:13
int CompareTo(bool value)
Definition Boolean.cs:104
readonly bool m_value
Definition Boolean.cs:11
static bool TryParse([NotNullWhen(true)] string? value, out bool result)
Definition Boolean.cs:161