Ejemplo n.º 1
0
        public bool TryMatchRepeatDeclaration(AttributeSyntax repeatAttributeSyntax, string expression)
        {
            var constEvaluator = new ConstantExpressionSyntaxEvaluator <string>();
            var patternName    = constEvaluator.Visit(repeatAttributeSyntax.ArgumentList.Arguments.First().Expression);

            // get the property from the current pattern generic definition.
            var repeatProperty = this.pattern.Properties.First(p => p.Name == patternName);

            return(AutomatedPropertyStrategy.Match(repeatProperty, expression));
        }
Ejemplo n.º 2
0
        public void RepeatDeclaration(
            AttributeSyntax repeatAttributeSyntax,
            Action <IAutomatedStrategy> callback)
        {
            var constEvaluator = new ConstantExpressionSyntaxEvaluator <string>();
            var patternName    = constEvaluator.Visit(repeatAttributeSyntax.ArgumentList.Arguments.First().Expression);

            var resolved = this.resolver.Resolve(patternName, this.pattern);

            // Check if this is self repeat pattern reference.
            if (object.ReferenceEquals(this.pattern, resolved))
            {
                callback(this);
                return;
            }

            // get the property from the current pattern generic definition.
            var repeatProperty = this.pattern.Properties.First(p => p.Name == patternName);

            ISelector selector;

            // Get the selector if any from the matching property.
            if (repeatProperty.SyntaxNodeProvider.SyntaxNode.AttributeLists
                .TryMatchAttributeName <PatternAttribute>(out var attributeSyntax))
            {
                selector = this.GetSelectorFromPatternAttribute(attributeSyntax);
            }
            else
            {
                selector = new AllPropertySelector();
            }

            foreach (var propertyDeclaration in selector.GetProperties(this.declaration))
            {
                var strategy = new AutomatedPropertyStrategy(repeatProperty, propertyDeclaration);

                callback(strategy);
            }
        }