using System.Globalization; namespace LoreSoft.MathExpressions { /// /// Class representing a constant number expression. /// public class NumberExpression : ExpressionBase { /// Initializes a new instance of the class. /// The number value for this expression. public NumberExpression(double value) { _value = value; base.Evaluate = delegate { return Value; }; } /// Gets the number of arguments this expression uses. /// The argument count. public override int ArgumentCount { get { return 0; } } private double _value; /// Gets the number value for this expression. /// The number value. public double Value { get { return _value; } } /// Determines whether the specified char is a number. /// The char to test. /// true if the specified char is a number; otherwise, false. /// This method checks if the char is a digit or a decimal separator. public static bool IsNumber(char c) { NumberFormatInfo f = CultureInfo.CurrentUICulture.NumberFormat; return char.IsDigit(c) || f.NumberDecimalSeparator.IndexOf(c) >= 0; } /// Determines whether the specified char is negative sign. /// The char to check. /// true if the specified char is negative sign; otherwise, false. public static bool IsNegativeSign(char c) { NumberFormatInfo f = CultureInfo.CurrentUICulture.NumberFormat; return f.NegativeSign.IndexOf(c) >= 0; } /// /// Returns a that represents the current . /// /// /// A that represents the current . /// /// 2 public override string ToString() { return _value.ToString(CultureInfo.CurrentCulture); } } }