示例#1
0
        /// <summary>
        /// Parses a value from a <see cref="string"/>.
        /// </summary>
        /// <param name="str">The <see cref="string"/> value.</param>
        /// <param name="result">The resulting value.</param>
        /// <returns><c>true</c> where <paramref name="str"/> was converted sucessfully; otherwise, <c>false</c>.</returns>
        public bool TryParse(string str, out bool result)
        {
            result = false;
            if (FalseValues.Contains(str, StringComparer))
            {
                return(true);
            }

            if (!TrueValues.Contains(str, StringComparer))
            {
                return(false);
            }

            result = true;
            return(true);
        }
示例#2
0
        private bool?ParseNullableBoolean(string from)
        {
            if (bool.TryParse(from, out var value))
            {
                return(value);
            }

            if (TrueValues.Contains(from))
            {
                return(true);
            }

            if (FalseValues.Contains(from))
            {
                return(false);
            }

            return(null);
        }
示例#3
0
 public override string ToString()
 {
     return($"'{TrueValues.First()}' or '{FalseValues.First()}'");
 }
示例#4
0
 static bool?Parse(string value)
 {
     return(TrueValues.Contains(value) ? true : (FalseValues.Contains(value) ? false : (bool?)null));
 }