/// <summary> /// Initialize a VariableOrNumber /// </summary> /// <param name="input">The name of the variable</param> /// <param name="cacheable">Whether the variable is cacheable</param> /// <param name="rpmComp">The RasterPropMonitorComputer that owns the variable</param> internal VariableOrNumber(string input, bool cacheable, RasterPropMonitorComputer rpmComp_) { string varName = input.Trim(); if (varName == "MetersToFeet") { varName = RPMGlobals.MetersToFeet.ToString(); } else if (varName == "MetersPerSecondToKnots") { varName = RPMGlobals.MetersPerSecondToKnots.ToString(); } else if (varName == "MetersPerSecondToFeetPerMinute") { varName = RPMGlobals.MetersPerSecondToFeetPerMinute.ToString(); } float realValue; if (float.TryParse(varName, out realValue)) { // If it's a numeric value, let's canonicalize it using // ToString, so we don't have duplicates that evaluate to the // same value (eg, 1.0, 1, 1.00, etc). variableName = realValue.ToString(); numericValue = realValue; isNumeric = true; variableType = VoNType.ConstantNumeric; } else if (input[0] == '$') { variableName = input; stringValue = input.Substring(1).Trim(); isNumeric = false; variableType = VoNType.ConstantString; } else { variableName = varName; variableType = VoNType.VariableValue; if (!cacheable) { rpmComp = rpmComp_; } } }
private VariableOrNumber(string input) { float realValue; if (float.TryParse(input, out realValue)) { numericValue = realValue; type = VoNType.ConstantNumeric; } else if (input[0] == '$') { stringValue = input.Substring(1); type = VoNType.ConstantString; } else { variableName = input.Trim(); type = VoNType.VariableValue; } }