﻿// Decompiled with JetBrains decompiler
// Type: System.Boolean
// Assembly: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 255ABCDF-D9D6-4E3D-BAD4-F74D4CE3D7A8
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll

using System.Runtime.InteropServices;

namespace System
{
  /// <summary>
  /// Represents a Boolean value.
  /// </summary>
  /// <filterpriority>1</filterpriority>
  [ComVisible(true)]
  [__DynamicallyInvokable]
  [Serializable]
  public struct Boolean : IComparable, IConvertible, IComparable<bool>, IEquatable<bool>
  {
    /// <summary>
    /// Represents the Boolean value true as a string. This field is read-only.
    /// </summary>
    /// <filterpriority>1</filterpriority>
    [__DynamicallyInvokable]
    public static readonly string TrueString = "True";
    /// <summary>
    /// Represents the Boolean value false as a string. This field is read-only.
    /// </summary>
    /// <filterpriority>1</filterpriority>
    [__DynamicallyInvokable]
    public static readonly string FalseString = "False";
    internal const int True = 1;
    internal const int False = 0;
    internal const string TrueLiteral = "True";
    internal const string FalseLiteral = "False";
    private bool m_value;

    /// <summary>
    /// Returns the hash code for this instance.
    /// </summary>
    /// 
    /// <returns>
    /// A hash code for the current <see cref="T:System.Boolean"/>.
    /// </returns>
    /// <filterpriority>2</filterpriority>
    [__DynamicallyInvokable]
    public override int GetHashCode()
    {
      return !this ? 0 : 1;
    }

    /// <summary>
    /// Converts the value of this instance to its equivalent string representation (either "True" or "False").
    /// </summary>
    /// 
    /// <returns>
    /// <see cref="F:System.Boolean.TrueString"/> if the value of this instance is true, or <see cref="F:System.Boolean.FalseString"/> if the value of this instance is false.
    /// </returns>
    /// <filterpriority>2</filterpriority>
    [__DynamicallyInvokable]
    public override string ToString()
    {
      return !this ? "False" : "True";
    }

    /// <summary>
    /// Converts the value of this instance to its equivalent string representation (either "True" or "False").
    /// </summary>
    /// 
    /// <returns>
    /// <see cref="F:System.Boolean.TrueString"/> if the value of this instance is true, or <see cref="F:System.Boolean.FalseString"/> if the value of this instance is false.
    /// </returns>
    /// <param name="provider">(Reserved) An <see cref="T:System.IFormatProvider"/> object. </param><filterpriority>2</filterpriority>
    public string ToString(IFormatProvider provider)
    {
      return !this ? "False" : "True";
    }

    /// <summary>
    /// Returns a value indicating whether this instance is equal to a specified object.
    /// </summary>
    /// 
    /// <returns>
    /// true if <paramref name="obj"/> is a <see cref="T:System.Boolean"/> and has the same value as this instance; otherwise, false.
    /// </returns>
    /// <param name="obj">An object to compare to this instance. </param><filterpriority>2</filterpriority>
    [__DynamicallyInvokable]
    public override bool Equals(object obj)
    {
      if (!(obj is bool))
        return false;
      return this == (bool) obj;
    }

    /// <summary>
    /// Returns a value indicating whether this instance is equal to a specified <see cref="T:System.Boolean"/> object.
    /// </summary>
    /// 
    /// <returns>
    /// true if <paramref name="obj"/> has the same value as this instance; otherwise, false.
    /// </returns>
    /// <param name="obj">A <see cref="T:System.Boolean"/> value to compare to this instance.</param><filterpriority>2</filterpriority>
    [__DynamicallyInvokable]
    public bool Equals(bool obj)
    {
      return this == obj;
    }

    /// <summary>
    /// Compares this instance to a specified object and returns an integer that indicates their relationship to one another.
    /// </summary>
    /// 
    /// <returns>
    /// A signed integer that indicates the relative order of this instance and <paramref name="obj"/>.Return Value Condition Less than zero This instance is false and <paramref name="obj"/> is true. Zero This instance and <paramref name="obj"/> are equal (either both are true or both are false). Greater than zero This instance is true and <paramref name="obj"/> is false.-or- <paramref name="obj"/> is null.
    /// </returns>
    /// <param name="obj">An object to compare to this instance, or null. </param><exception cref="T:System.ArgumentException"><paramref name="obj"/> is not a <see cref="T:System.Boolean"/>. </exception><filterpriority>2</filterpriority>
    public int CompareTo(object obj)
    {
      if (obj == null)
        return 1;
      if (!(obj is bool))
        throw new ArgumentException(Environment.GetResourceString("Arg_MustBeBoolean"));
      if (this == (bool) obj)
        return 0;
      return !this ? -1 : 1;
    }

    /// <summary>
    /// Compares this instance to a specified <see cref="T:System.Boolean"/> object and returns an integer that indicates their relationship to one another.
    /// </summary>
    /// 
    /// <returns>
    /// A signed integer that indicates the relative values of this instance and <paramref name="value"/>.Return Value Condition Less than zero This instance is false and <paramref name="value"/> is true. Zero This instance and <paramref name="value"/> are equal (either both are true or both are false). Greater than zero This instance is true and <paramref name="value"/> is false.
    /// </returns>
    /// <param name="value">A <see cref="T:System.Boolean"/> object to compare to this instance. </param><filterpriority>2</filterpriority>
    [__DynamicallyInvokable]
    public int CompareTo(bool value)
    {
      if (this == value)
        return 0;
      return !this ? -1 : 1;
    }

    /// <summary>
    /// Converts the specified string representation of a logical value to its <see cref="T:System.Boolean"/> equivalent, or throws an exception if the string is not equivalent to the value of <see cref="F:System.Boolean.TrueString"/> or <see cref="F:System.Boolean.FalseString"/>.
    /// </summary>
    /// 
    /// <returns>
    /// true if <paramref name="value"/> is equivalent to the value of the <see cref="F:System.Boolean.TrueString"/> field; false if <paramref name="value"/> is equivalent to the value of the <see cref="F:System.Boolean.FalseString"/> field.
    /// </returns>
    /// <param name="value">A string containing the value to convert. </param><exception cref="T:System.ArgumentNullException"><paramref name="value"/> is null. </exception><exception cref="T:System.FormatException"><paramref name="value"/> is not equivalent to the value of the <see cref="F:System.Boolean.TrueString"/> or <see cref="F:System.Boolean.FalseString"/> field. </exception><filterpriority>1</filterpriority>
    [__DynamicallyInvokable]
    public static bool Parse(string value)
    {
      if (value == null)
        throw new ArgumentNullException("value");
      bool result = false;
      if (!bool.TryParse(value, out result))
        throw new FormatException(Environment.GetResourceString("Format_BadBoolean"));
      return result;
    }

    /// <summary>
    /// Tries to convert the specified string representation of a logical value to its <see cref="T:System.Boolean"/> equivalent. A return value indicates whether the conversion succeeded or failed.
    /// </summary>
    /// 
    /// <returns>
    /// true if <paramref name="value"/> was converted successfully; otherwise, false.
    /// </returns>
    /// <param name="value">A string containing the value to convert. </param><param name="result">When this method returns, if the conversion succeeded, contains true if <paramref name="value"/> is equivalent to <see cref="F:System.Boolean.TrueString"/> or false if <paramref name="value"/> is equivalent to <see cref="F:System.Boolean.FalseString"/>. If the conversion failed, contains false. The conversion fails if <paramref name="value"/> is null or is not equivalent to the value of either the <see cref="F:System.Boolean.TrueString"/> or <see cref="F:System.Boolean.FalseString"/> field.</param><filterpriority>1</filterpriority>
    [__DynamicallyInvokable]
    public static bool TryParse(string value, out bool result)
    {
      result = false;
      if (value == null)
        return false;
      if ("True".Equals(value, StringComparison.OrdinalIgnoreCase))
      {
        result = true;
        return true;
      }
      if ("False".Equals(value, StringComparison.OrdinalIgnoreCase))
      {
        result = false;
        return true;
      }
      value = bool.TrimWhiteSpaceAndNull(value);
      if ("True".Equals(value, StringComparison.OrdinalIgnoreCase))
      {
        result = true;
        return true;
      }
      if (!"False".Equals(value, StringComparison.OrdinalIgnoreCase))
        return false;
      result = false;
      return true;
    }

    /// <summary>
    /// Returns the <see cref="T:System.TypeCode"/> for value type <see cref="T:System.Boolean"/>.
    /// </summary>
    /// 
    /// <returns>
    /// The enumerated constant, <see cref="F:System.TypeCode.Boolean"/>.
    /// </returns>
    /// <filterpriority>2</filterpriority>
    public TypeCode GetTypeCode()
    {
      return TypeCode.Boolean;
    }

    bool IConvertible.ToBoolean(IFormatProvider provider)
    {
      return this;
    }

    char IConvertible.ToChar(IFormatProvider provider)
    {
      throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", (object) "Boolean", (object) "Char"));
    }

    sbyte IConvertible.ToSByte(IFormatProvider provider)
    {
      return Convert.ToSByte(this);
    }

    byte IConvertible.ToByte(IFormatProvider provider)
    {
      return Convert.ToByte(this);
    }

    short IConvertible.ToInt16(IFormatProvider provider)
    {
      return Convert.ToInt16(this);
    }

    ushort IConvertible.ToUInt16(IFormatProvider provider)
    {
      return Convert.ToUInt16(this);
    }

    int IConvertible.ToInt32(IFormatProvider provider)
    {
      return Convert.ToInt32(this);
    }

    uint IConvertible.ToUInt32(IFormatProvider provider)
    {
      return Convert.ToUInt32(this);
    }

    long IConvertible.ToInt64(IFormatProvider provider)
    {
      return Convert.ToInt64(this);
    }

    ulong IConvertible.ToUInt64(IFormatProvider provider)
    {
      return Convert.ToUInt64(this);
    }

    float IConvertible.ToSingle(IFormatProvider provider)
    {
      return Convert.ToSingle(this);
    }

    double IConvertible.ToDouble(IFormatProvider provider)
    {
      return Convert.ToDouble(this);
    }

    Decimal IConvertible.ToDecimal(IFormatProvider provider)
    {
      return Convert.ToDecimal(this);
    }

    DateTime IConvertible.ToDateTime(IFormatProvider provider)
    {
      throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", (object) "Boolean", (object) "DateTime"));
    }

    object IConvertible.ToType(Type type, IFormatProvider provider)
    {
      return Convert.DefaultToType((IConvertible) (bool) (this ? 1 : 0), type, provider);
    }

    private static string TrimWhiteSpaceAndNull(string value)
    {
      int startIndex = 0;
      int index = value.Length - 1;
      char ch = char.MinValue;
      while (startIndex < value.Length && (char.IsWhiteSpace(value[startIndex]) || (int) value[startIndex] == (int) ch))
        ++startIndex;
      while (index >= startIndex && (char.IsWhiteSpace(value[index]) || (int) value[index] == (int) ch))
        --index;
      return value.Substring(startIndex, index - startIndex + 1);
    }
  }
}
