| File: Evaluation\Conditionals\NumericExpressionNode.cs | Web Access |
| Project: src\msbuild\src\Build\Microsoft.Build.csproj (Microsoft.Build) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; using System.Diagnostics; using Microsoft.Build.Shared; namespace Microsoft.Build.Evaluation { /// <summary> /// Represents a number - evaluates as numeric. /// </summary> [DebuggerDisplay("{DebuggerDisplay,nq}")] internal sealed class NumericExpressionNode : OperandExpressionNode { private readonly string _value; internal NumericExpressionNode(string value) { Assumed.NotNullOrEmpty(value, "NumericExpressionNode cannot have empty value"); _value = value; } internal override bool TryBoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, out bool result) { result = default; return false; } internal override bool TryNumericEvaluate(ConditionEvaluator.IConditionEvaluationState state, out double result) { return ConversionUtilities.TryConvertDecimalOrHexToDouble(_value, out result); } internal override bool TryVersionEvaluate(ConditionEvaluator.IConditionEvaluationState state, out Version? result) { return Version.TryParse(_value, out result); } /// <inheritdoc cref="GenericExpressionNode"/> internal override bool IsUnexpandedValueEmpty() => false; /// <summary> /// Get the unexpanded value /// </summary> internal override string GetUnexpandedValue(ConditionEvaluator.IConditionEvaluationState state) { return _value; } /// <summary> /// Get the expanded value /// </summary> internal override string GetExpandedValue(ConditionEvaluator.IConditionEvaluationState state) { return _value; } /// <summary> /// If any expression nodes cache any state for the duration of evaluation, /// now's the time to clean it up /// </summary> internal override void ResetState() { } internal override string DebuggerDisplay => $"#\"{_value}\")"; } }