-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
GreaterThanExpressionNode.cs
66 lines (57 loc) · 2.22 KB
/
GreaterThanExpressionNode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics;
#nullable disable
namespace Microsoft.Build.Evaluation
{
/// <summary>
/// Compares for left > right
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
internal sealed class GreaterThanExpressionNode : NumericComparisonExpressionNode
{
/// <summary>
/// Compare numerically
/// </summary>
protected override bool Compare(double left, double right)
{
return left > right;
}
/// <summary>
/// Compare Versions. This is only intended to compare version formats like "A.B.C.D" which can otherwise not be compared numerically
/// </summary>
/// <returns></returns>
protected override bool Compare(Version left, Version right)
{
return left > right;
}
/// <summary>
/// Compare mixed numbers and Versions
/// </summary>
protected override bool Compare(Version left, double right)
{
if (left.Major != right)
{
return left.Major > right;
}
// If they have same "major" number, then that means we are comparing something like "6.X.Y.Z" to "6". Version treats the objects with more dots as
// "larger" regardless of what those dots are (e.g. 6.0.0.0 > 6 is a true statement)
return true;
}
/// <summary>
/// Compare mixed numbers and Versions
/// </summary>
protected override bool Compare(double left, Version right)
{
if (right.Major != left)
{
return left > right.Major;
}
// If they have same "major" number, then that means we are comparing something like "6.X.Y.Z" to "6". Version treats the objects with more dots as
// "larger" regardless of what those dots are (e.g. 6.0.0.0 > 6 is a true statement)
return false;
}
internal override string DebuggerDisplay => $"(> {LeftChild.DebuggerDisplay} {RightChild.DebuggerDisplay})";
}
}