Beispiel #1
0
        private static bool HasIllegalPatternVariables(
            AnalyzedPattern pattern,
            bool permitDesignations = true,
            bool isTopLevel         = false
            )
        {
            switch (pattern)
            {
            case Not p:
                return(HasIllegalPatternVariables(p.Pattern, permitDesignations: isTopLevel));

            case Binary p:
                if (p.IsDisjunctive)
                {
                    permitDesignations = false;
                }
                return(HasIllegalPatternVariables(p.Left, permitDesignations) ||
                       HasIllegalPatternVariables(p.Right, permitDesignations));

            case Source p when !permitDesignations:
                return(p.PatternSyntax
                       .DescendantNodes()
                       .OfType <SingleVariableDesignationSyntax>()
                       .Any(variable => !variable.Identifier.IsMissing));

            default:
                return(false);
            }
        }
Beispiel #2
0
            public static AnalyzedPattern?TryCreate(AnalyzedPattern leftPattern, AnalyzedPattern rightPattern, bool isDisjunctive, SyntaxToken token)
            {
                var target = leftPattern.Target;

                if (!SyntaxFactory.AreEquivalent(target.Syntax, rightPattern.Target.Syntax))
                {
                    return(null);
                }

                return(new Binary(leftPattern, rightPattern, isDisjunctive, token, target));
            }
Beispiel #3
0
 private Not(AnalyzedPattern pattern, IOperation target) : base(target)
     => Pattern = pattern;