mscorlib(4.0.0.0) API with additions
Boolean.cs
3 
4 namespace System
5 {
8  [ComVisible(true)]
9  [__DynamicallyInvokable]
10  public struct Boolean : IComparable, IConvertible, IComparable<bool>, IEquatable<bool>
11  {
12  private bool m_value;
13 
14  internal const int True = 1;
15 
16  internal const int False = 0;
17 
18  internal const string TrueLiteral = "True";
19 
20  internal const string FalseLiteral = "False";
21 
23  [__DynamicallyInvokable]
24  public static readonly string TrueString = "True";
25 
27  [__DynamicallyInvokable]
28  public static readonly string FalseString = "False";
29 
32  [__DynamicallyInvokable]
33  public override int GetHashCode()
34  {
35  if (!this)
36  {
37  return 0;
38  }
39  return 1;
40  }
41 
44  [__DynamicallyInvokable]
45  public override string ToString()
46  {
47  if (!this)
48  {
49  return "False";
50  }
51  return "True";
52  }
53 
58  public string ToString(IFormatProvider provider)
59  {
60  if (!this)
61  {
62  return "False";
63  }
64  return "True";
65  }
66 
71  [__DynamicallyInvokable]
72  public override bool Equals(object obj)
73  {
74  if (!(obj is bool))
75  {
76  return false;
77  }
78  return this == (bool)obj;
79  }
80 
85  [NonVersionable]
86  [__DynamicallyInvokable]
87  public bool Equals(bool obj)
88  {
89  return this == obj;
90  }
91 
98  public int CompareTo(object obj)
99  {
100  if (obj == null)
101  {
102  return 1;
103  }
104  if (!(obj is bool))
105  {
106  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeBoolean"));
107  }
108  if (this == (bool)obj)
109  {
110  return 0;
111  }
112  if (!this)
113  {
114  return -1;
115  }
116  return 1;
117  }
118 
122  [__DynamicallyInvokable]
123  public int CompareTo(bool value)
124  {
125  if (this == value)
126  {
127  return 0;
128  }
129  if (!this)
130  {
131  return -1;
132  }
133  return 1;
134  }
135 
144  [__DynamicallyInvokable]
145  public static bool Parse(string value)
146  {
147  if (value == null)
148  {
149  throw new ArgumentNullException("value");
150  }
151  bool result = false;
152  if (!TryParse(value, out result))
153  {
154  throw new FormatException(Environment.GetResourceString("Format_BadBoolean"));
155  }
156  return result;
157  }
158 
164  [__DynamicallyInvokable]
165  public static bool TryParse(string value, out bool result)
166  {
167  result = false;
168  if (value == null)
169  {
170  return false;
171  }
172  if ("True".Equals(value, StringComparison.OrdinalIgnoreCase))
173  {
174  result = true;
175  return true;
176  }
177  if ("False".Equals(value, StringComparison.OrdinalIgnoreCase))
178  {
179  result = false;
180  return true;
181  }
182  value = TrimWhiteSpaceAndNull(value);
183  if ("True".Equals(value, StringComparison.OrdinalIgnoreCase))
184  {
185  result = true;
186  return true;
187  }
188  if ("False".Equals(value, StringComparison.OrdinalIgnoreCase))
189  {
190  result = false;
191  return true;
192  }
193  return false;
194  }
195 
196  private static string TrimWhiteSpaceAndNull(string value)
197  {
198  int i = 0;
199  int num = value.Length - 1;
200  char c;
201  for (c = '\0'; i < value.Length && (char.IsWhiteSpace(value[i]) || value[i] == c); i++)
202  {
203  }
204  while (num >= i && (char.IsWhiteSpace(value[num]) || value[num] == c))
205  {
206  num--;
207  }
208  return value.Substring(i, num - i + 1);
209  }
210 
214  {
215  return TypeCode.Boolean;
216  }
217 
222  [__DynamicallyInvokable]
224  {
225  return this;
226  }
227 
232  [__DynamicallyInvokable]
234  {
235  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "Boolean", "Char"));
236  }
237 
241  [__DynamicallyInvokable]
243  {
244  return Convert.ToSByte(this);
245  }
246 
250  [__DynamicallyInvokable]
252  {
253  return Convert.ToByte(this);
254  }
255 
259  [__DynamicallyInvokable]
261  {
262  return Convert.ToInt16(this);
263  }
264 
268  [__DynamicallyInvokable]
270  {
271  return Convert.ToUInt16(this);
272  }
273 
277  [__DynamicallyInvokable]
279  {
280  return Convert.ToInt32(this);
281  }
282 
286  [__DynamicallyInvokable]
288  {
289  return Convert.ToUInt32(this);
290  }
291 
295  [__DynamicallyInvokable]
297  {
298  return Convert.ToInt64(this);
299  }
300 
304  [__DynamicallyInvokable]
306  {
307  return Convert.ToUInt64(this);
308  }
309 
313  [__DynamicallyInvokable]
315  {
316  return Convert.ToSingle(this);
317  }
318 
322  [__DynamicallyInvokable]
324  {
325  return Convert.ToDouble(this);
326  }
327 
331  [__DynamicallyInvokable]
333  {
334  return Convert.ToDecimal(this);
335  }
336 
341  [__DynamicallyInvokable]
343  {
344  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "Boolean", "DateTime"));
345  }
346 
354  [__DynamicallyInvokable]
355  object IConvertible.ToType(Type type, IFormatProvider provider)
356  {
357  return Convert.DefaultToType(this, type, provider);
358  }
359  }
360 }
float ToSingle(IFormatProvider provider)
Converts the value of this instance to an equivalent single-precision floating-point number using the...
Converts a base data type to another base data type.
Definition: Convert.cs:10
static long ToInt64(object value)
Converts the value of the specified object to a 64-bit signed integer.
Definition: Convert.cs:2506
static double ToDouble(object value)
Converts the value of the specified object to a double-precision floating-point number.
Definition: Convert.cs:3189
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
int CompareTo(bool value)
Compares this instance to a specified T:System.Boolean object and returns an integer that indicates t...
Definition: Boolean.cs:123
double ToDouble(IFormatProvider provider)
Converts the value of this instance to an equivalent double-precision floating-point number using the...
static readonly string FalseString
Represents the Boolean value false as a string. This field is read-only.
Definition: Boolean.cs:28
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
bool ToBoolean(IFormatProvider provider)
Converts the value of this instance to an equivalent Boolean value using the specified culture-specif...
TypeCode
Specifies the type of an object.
Definition: TypeCode.cs:9
static float ToSingle(object value)
Converts the value of the specified object to a single-precision floating-point number.
Definition: Convert.cs:2982
Definition: __Canon.cs:3
The exception that is thrown for invalid casting or explicit conversion.
char ToChar(IFormatProvider provider)
Converts the value of this instance to an equivalent Unicode character using the specified culture-sp...
Provides a mechanism for retrieving an object to control formatting.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
DateTime ToDateTime(IFormatProvider provider)
Converts the value of this instance to an equivalent T:System.DateTime using the specified culture-sp...
sbyte ToSByte(IFormatProvider provider)
Converts the value of this instance to an equivalent 8-bit signed integer using the specified culture...
Defines a generalized type-specific comparison method that a value type or class implements to order ...
Definition: IComparable.cs:8
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
decimal ToDecimal(IFormatProvider provider)
Converts the value of this instance to an equivalent T:System.Decimal number using the specified cult...
The exception that is thrown when the format of an argument is invalid, or when a composite format st...
int ToInt32(IFormatProvider provider)
Converts the value of this instance to an equivalent 32-bit signed integer using the specified cultur...
override bool Equals(object obj)
Returns a value indicating whether this instance is equal to a specified object.
Definition: Boolean.cs:72
static ushort ToUInt16(object value)
Converts the value of the specified object to a 16-bit unsigned integer.
Definition: Convert.cs:1707
object ToType(Type conversionType, IFormatProvider provider)
Converts the value of this instance to an T:System.Object of the specified T:System....
static bool Parse(string value)
Converts the specified string representation of a logical value to its T:System.Boolean equivalent.
Definition: Boolean.cs:145
static sbyte ToSByte(object value)
Converts the value of the specified object to an 8-bit signed integer.
Definition: Convert.cs:909
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
ushort ToUInt16(IFormatProvider provider)
Converts the value of this instance to an equivalent 16-bit unsigned integer using the specified cult...
override string ToString()
Converts the value of this instance to its equivalent string representation (either "True" or "False"...
Definition: Boolean.cs:45
static uint ToUInt32(object value)
Converts the value of the specified object to a 32-bit unsigned integer.
Definition: Convert.cs:2235
short ToInt16(IFormatProvider provider)
Converts the value of this instance to an equivalent 16-bit signed integer using the specified cultur...
static decimal ToDecimal(object value)
Converts the value of the specified object to an equivalent decimal number.
Definition: Convert.cs:3394
long ToInt64(IFormatProvider provider)
Converts the value of this instance to an equivalent 64-bit signed integer using the specified cultur...
The exception that is thrown when one of the arguments provided to a method is not valid.
static bool TryParse(string value, out bool result)
Tries to convert the specified string representation of a logical value to its T:System....
Definition: Boolean.cs:165
int CompareTo(object obj)
Compares this instance to a specified object and returns an integer that indicates their relationship...
Definition: Boolean.cs:98
static byte ToByte(object value)
Converts the value of the specified object to an 8-bit unsigned integer.
Definition: Convert.cs:1186
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: IEquatable.cs:6
TypeCode GetTypeCode()
Returns the type code for the T:System.Boolean value type.
Definition: Boolean.cs:213
static short ToInt16(object value)
Converts the value of the specified object to a 16-bit signed integer.
Definition: Convert.cs:1452
Specifies that the class can be serialized.
Represents a Boolean (true or false) value.
Definition: Boolean.cs:10
ulong ToUInt64(IFormatProvider provider)
Converts the value of this instance to an equivalent 64-bit unsigned integer using the specified cult...
static ulong ToUInt64(object value)
Converts the value of the specified object to a 64-bit unsigned integer.
Definition: Convert.cs:2727
static int ToInt32(object value)
Converts the value of the specified object to a 32-bit signed integer.
Definition: Convert.cs:1974
bool Equals(bool obj)
Returns a value indicating whether this instance is equal to a specified T:System....
Definition: Boolean.cs:87
byte ToByte(IFormatProvider provider)
Converts the value of this instance to an equivalent 8-bit unsigned integer using the specified cultu...
Defines methods that convert the value of the implementing reference or value type to a common langua...
Definition: IConvertible.cs:9
static readonly string TrueString
Represents the Boolean value true as a string. This field is read-only.
Definition: Boolean.cs:24
override int GetHashCode()
Returns the hash code for this instance.
Definition: Boolean.cs:33
uint ToUInt32(IFormatProvider provider)
Converts the value of this instance to an equivalent 32-bit unsigned integer using the specified cult...
string ToString(IFormatProvider provider)
Converts the value of this instance to its equivalent string representation (either "True" or "False"...
Definition: Boolean.cs:58