2 using System.Globalization;
4 namespace Mercury.Interpreting
55 if (value == null)
throw new ArgumentNullException(
"value");
64 public object Value {
get;
protected set; }
100 int ip;
double dp;
bool bp;
102 var culture = CultureInfo.InvariantCulture;
103 if (
int.TryParse(value, NumberStyles.Integer, culture, out ip))
104 return IntegralParameter(ip);
105 else if (
double.TryParse(value, NumberStyles.Float, culture, out dp))
106 return RealParameter(dp);
107 else if (
bool.TryParse(value, out bp))
108 return BooleanParameter(bp);
110 return StringParameter(value);
120 return (cp == null) ?
false : Equals(cp);
124 {
return (((
int) Type) + 1) * Value.GetHashCode(); }
127 {
return Type == ParameterType.StringConstant ?
"\"" + Value.ToString() +
"\"" : Value.ToString(); }
133 #region [ IFormalParameter ]
139 #region [ IEquatable ]
143 return (other != null)
144 && (Type == other.Type)
145 && (Value.Equals(other.
Value));
172 throw new ArgumentException(
string.Format(
"Invalid variable name '{0}'", name));
175 Type = ParameterType.Variable;
181 public string Name {
get;
private set; }
190 return vp == null ?
false : Equals(vp);
194 {
return Name.GetHashCode(); }
197 {
return "#" + Name; }
203 #region [ IFormalParameter ]
209 #region [ IEquatable ]
212 {
return (other != null) && (Name.Equals(other.Name)); }
bool Equals(VariableParameter other)
override int GetHashCode()
override string ToString()
override int GetHashCode()
Represents a named parameter that will be replaced by an actual value of a variable captured by inter...
bool Equals(ConstantParameter other)
ConstantParameter(object value, ParameterType type)
Creates a new ConstantParameter instance.
static bool IsValidName(string name)
Determines whether the specified string is a valid variable name.
static ConstantParameter IntegralParameter(int value)
Creates a new integral constant parameter.
static ConstantParameter StringParameter(string value)
Creates a new string constant parameter.
Represents a variable element that captures value and can be used on the RHS of the RewriteRule as an...
override bool Equals(object obj)
VariableParameter(string name)
Creates a new Mercury.Interpreting.VariableParameter instance.
static ConstantParameter AutoCreate(string value)
Tries to parse the string value and infers its type.
override string ToString()
static ConstantParameter BooleanParameter(bool value)
Creates a new boolean constant parameter
ParameterType
Formal Parameter Type
static ConstantParameter RealParameter(double value)
Creates a new real constant parameter.
override bool Equals(object obj)
object Value
Value of this constant