Beispiel #1
0
        public override bool TryEvaluateToBool(IExpressionContext context, out bool result)
        {
            if (left.TryEvaluateToBool(context, out bool l) && right.TryEvaluateToBool(context, out bool r))
            {
                result = BoolCompare(l, r, op);
                return(true);
            }

            if (left.TryEvaluateToVersion(context, out Version vl))
            {
                if (right.TryEvaluateToVersion(context, out Version vr))
                {
                    result = VersionCompare(vl, vr, op);
                    return(true);
                }
                else if (right.TryEvaluateToNumber(context, out float fr))
                {
                    result = VersionCompare(vl, fr, op);
                    return(true);
                }
            }
            else if (left.TryEvaluateToNumber(context, out float fl))
            {
                if (right.TryEvaluateToNumber(context, out float fr))
                {
                    result = NumberCompare(fl, fr, op);
                    return(true);
                }
                else if (right.TryEvaluateToVersion(context, out Version vr))
                {
                    result = VersionCompare(fl, vr, op);
                    return(true);
                }
            }

            if (!left.TryEvaluateToString(context, out string ls) || !right.TryEvaluateToString(context, out string rs))
            {
                result = false;
                return(false);
            }

            result = StringCompare(ls, rs, op);
            return(true);
        }
Beispiel #2
0
        public override bool TryEvaluateToBool(IExpressionContext context, out bool result)
        {
            if (left.TryEvaluateToBool(context, out bool l) && right.TryEvaluateToBool(context, out bool r))
            {
                result = BoolCompare(l, r, op);
                return(true);
            }

            if (left.TryEvaluateToVersion(context, out Version vl))
            {
                if (right.TryEvaluateToVersion(context, out Version vr))
                {
                    result = VersionCompare(vl, vr, op);
                    return(true);
                }
                else if (right.TryEvaluateToNumber(context, out float fr))
                {
                    result = VersionCompare(vl, fr, op);
                    return(true);
                }
            }
            else if (left.TryEvaluateToNumber(context, out float fl))
            {
                if (right.TryEvaluateToNumber(context, out float fr))
                {
                    result = NumberCompare(fl, fr, op);
                    return(true);
                }
                else if (right.TryEvaluateToVersion(context, out Version vr))
                {
                    result = VersionCompare(fl, vr, op);
                    return(true);
                }
            }

            if (!left.TryEvaluateToString(context, out string ls) || !right.TryEvaluateToString(context, out string rs))
            {
                result = false;
                return(false);
            }

            // Special case MSBuildToolsVersion when it is set to Current.
            if (op != RelationOperator.Equal || op != RelationOperator.NotEqual)
            {
                if (IsMSBuildCurrentToolsVersion(left, ls))
                {
                    if (TryGetVisualStudioVersion(context, out vl))
                    {
                        if (right.TryEvaluateToVersion(context, out Version vr))
                        {
                            result = VersionCompare(vl, vr, op);
                            return(true);
                        }
                        else if (right.TryEvaluateToNumber(context, out float fr))
                        {
                            result = VersionCompare(vl, fr, op);
                            return(true);
                        }
                    }
                }
                else if (IsMSBuildCurrentToolsVersion(right, rs))
                {
                    if (TryGetVisualStudioVersion(context, out Version vr))
                    {
                        if (left.TryEvaluateToVersion(context, out vl))
                        {
                            result = VersionCompare(vl, vr, op);
                            return(true);
                        }
                        else if (left.TryEvaluateToNumber(context, out float fl))
                        {
                            result = VersionCompare(fl, vr, op);
                            return(true);
                        }
                    }
                }
            }

            result = StringCompare(ls, rs, op);
            return(true);
        }