Esempio n. 1
0
 public WithOperator(NuGetLicense license, NuGetLicenseException exception) :
     base(LicenseOperatorType.WithOperator)
 {
     License   = license ?? throw new ArgumentNullException(nameof(license));
     Exception = exception ?? throw new ArgumentNullException(nameof(exception));
 }
Esempio n. 2
0
        private static void ProcessOperators(Stack <LicenseExpressionToken> operatorStack, Stack <Tuple <bool, object> > operandStack)
        {
            var op           = operatorStack.Pop();
            var rightOperand = PopIfNotEmpty(operandStack);
            var leftOperand  = PopIfNotEmpty(operandStack);

            if (op.TokenType == LicenseTokenType.WITH)
            {
                if (!(rightOperand.Item1 == leftOperand.Item1 == true))
                {
                    throw new NuGetLicenseExpressionParsingException(string.Format(CultureInfo.CurrentCulture, Strings.NuGetLicenseExpression_InvalidExpression));
                }
                var right = rightOperand.Item2 as LicenseExpressionToken;
                var left  = leftOperand.Item2 as LicenseExpressionToken;

                var withNode = new WithOperator(NuGetLicense.ParseIdentifier(left.Value), NuGetLicenseException.ParseIdentifier(right.Value));

                operandStack.Push(new Tuple <bool, object>(false, withNode));
            }
            else
            {
                var logicalOperator = op.TokenType == LicenseTokenType.AND ? LogicalOperatorType.And : LogicalOperatorType.Or;

                var right = rightOperand.Item1 ?
                            NuGetLicense.ParseIdentifier(((LicenseExpressionToken)rightOperand.Item2).Value) :
                            (NuGetLicenseExpression)rightOperand.Item2;

                var left = leftOperand.Item1 ?
                           NuGetLicense.ParseIdentifier(((LicenseExpressionToken)leftOperand.Item2).Value) :
                           (NuGetLicenseExpression)leftOperand.Item2;

                var newExpression = new LogicalOperator(logicalOperator, left, right);
                operandStack.Push(new Tuple <bool, object>(false, newExpression));
            }
        }