internal override bool CanNumericEvaluate(ConditionEvaluationState state) { // It is not always possible to numerically evaluate even a numerical expression - // for example, it may overflow a double. So check here. return(ConversionUtilities.ValidDecimalOrHexNumber(value)); }
internal override string GetExpandedValue(ConditionEvaluationState state) { return(value); }
/// <summary> /// Evaluate as numeric /// </summary> internal override double NumericEvaluate(ConditionEvaluationState state) { return(ConversionUtilities.ConvertDecimalOrHexToDouble(value)); }
/// <summary> /// Whether it can be evaluated as a boolean: never allowed for numerics /// </summary> internal override bool CanBoolEvaluate(ConditionEvaluationState state) { // Numeric expressions are never allowed to be treated as booleans. return(false); }
/// <summary> /// Value before any item and property expressions are expanded /// </summary> /// <returns></returns> internal override string GetUnexpandedValue(ConditionEvaluationState state) { return(null); }
/// <summary> /// Evaluate as boolean /// </summary> internal override bool BoolEvaluate(ConditionEvaluationState state) { // Should be unreachable: all calls check CanBoolEvaluate() first ErrorUtilities.VerifyThrow(false, "Can't evaluate a numeric expression as boolean."); return(false); }
/// <summary> /// Whether boolean evaluation is allowed: always allowed for operators /// </summary> internal override bool CanBoolEvaluate(ConditionEvaluationState state) { return(true); }
internal abstract bool BoolEvaluate(ConditionEvaluationState state);
/// <summary> /// Evaluate node as boolean /// </summary> internal override bool BoolEvaluate(ConditionEvaluationState state) { if (String.Compare(functionName, "exists", StringComparison.OrdinalIgnoreCase) == 0) { // Check we only have one argument VerifyArgumentCount(1, state); // Expand properties and items, and verify the result is an appropriate scalar string expandedValue = ExpandArgumentForScalarParameter("exists", (GenericExpressionNode)arguments[0], state); if (Project.PerThreadProjectDirectory != null && !String.IsNullOrEmpty(expandedValue)) { try { expandedValue = Path.GetFullPath(Path.Combine(Project.PerThreadProjectDirectory, expandedValue)); } catch (Exception e) // Catching Exception, but rethrowing unless it's an IO related exception. { if (ExceptionHandling.NotExpectedException(e)) { throw; } // Ignore invalid characters or path related exceptions // We will ignore the PathTooLong exception caused by GetFullPath becasue in single proc this code // is not executed and the condition is just evaluated to false as File.Exists and Directory.Exists does not throw in this situation. // To be consistant with that we will return a false in this case also. // DevDiv Bugs: 46035 return(false); } } // Both Exists functions return false if the value is null or empty return(File.Exists(expandedValue) || Directory.Exists(expandedValue)); } else if (String.Compare(functionName, "HasTrailingSlash", StringComparison.OrdinalIgnoreCase) == 0) { // Check we only have one argument VerifyArgumentCount(1, state); // Expand properties and items, and verify the result is an appropriate scalar string expandedValue = ExpandArgumentForScalarParameter("HasTrailingSlash", (GenericExpressionNode)arguments[0], state); // Is the last character a backslash? if (expandedValue.Length != 0) { char lastCharacter = expandedValue[expandedValue.Length - 1]; // Either back or forward slashes satisfy the function: this is useful for URL's return(lastCharacter == Path.DirectorySeparatorChar || lastCharacter == Path.AltDirectorySeparatorChar); } else { return(false); } } // We haven't implemented any other "functions" else { ProjectErrorUtilities.VerifyThrowInvalidProject( false, state.conditionAttribute, "UndefinedFunctionCall", state.parsedCondition, this.functionName); return(false); } }
/// <summary> /// Numeric evaluation is never allowed for operators /// </summary> internal override double NumericEvaluate(ConditionEvaluationState state) { // Should be unreachable: all calls check CanNumericEvaluate() first ErrorUtilities.VerifyThrow(false, "Cannot numeric evaluate an operator"); return(0.0D); }
/// <summary> /// Expands properties and items in the argument, and verifies that the result is consistent /// with a scalar parameter type. /// </summary> /// <param name="function">Function name for errors</param> /// <param name="argumentNode">Argument to be expanded</param> /// <returns>Scalar result</returns> /// <owner>danmose</owner> private string ExpandArgumentForScalarParameter(string function, GenericExpressionNode argumentNode, ConditionEvaluationState state) { string argument = argumentNode.GetUnexpandedValue(state); List <TaskItem> items = state.expanderToUse.ExpandAllIntoTaskItems(argument, state.conditionAttribute); string expandedValue = String.Empty; if (items.Count == 0) { // Empty argument, that's fine. } else if (items.Count == 1) { expandedValue = items[0].ItemSpec; } else // too many items for the function { // We only allow a single item to be passed into a scalar parameter. ProjectErrorUtilities.VerifyThrowInvalidProject(false, state.conditionAttribute, "CannotPassMultipleItemsIntoScalarFunction", function, argument, state.expanderToUse.ExpandAllIntoString(argument, state.conditionAttribute)); } return(expandedValue); }
/// <summary> /// Value before any item and property expressions are expanded /// </summary> /// <returns></returns> internal abstract string GetUnexpandedValue(ConditionEvaluationState state);
internal abstract double NumericEvaluate(ConditionEvaluationState state);
internal override bool CanBoolEvaluate(ConditionEvaluationState state) { return(LeftChild.CanBoolEvaluate(state)); }
/// <summary> /// Whether the node can be evaluated as a numeric: by default, /// this is not allowed /// </summary> internal override bool CanNumericEvaluate(ConditionEvaluationState state) { return(false); }
/// <summary> /// Returns expanded value with '!' prepended. Useful for error messages. /// </summary> internal override string GetExpandedValue(ConditionEvaluationState state) { return("!" + LeftChild.GetExpandedValue(state)); }
internal abstract bool CanNumericEvaluate(ConditionEvaluationState state);