public void NameOfConstEvaluatorTest(string textExpression, string expectedValue) { var walker = new ConstantExpressionSyntaxEvaluator <string>(); var exp = SyntaxTreeHelper.GetExpressionSyntax($"nameof({textExpression})"); var value = walker.Visit(exp); Assert.Equal(expectedValue, value); }
public void SimpleStringConstEvaluatorTest() { var textValue = "MyValue"; var walker = new ConstantExpressionSyntaxEvaluator <string>(); var exp = SyntaxTreeHelper.GetExpressionSyntax($@"""{textValue}"""); var value = walker.Visit(exp); Assert.Equal(textValue, value); }
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)); }
public void RepeatDeclaration( AttributeSyntax repeatAttributeSyntax, Action <IAutomatedStrategy> callback) { var constEvaluator = new ConstantExpressionSyntaxEvaluator <string>(); var patternName = constEvaluator.Visit(repeatAttributeSyntax.ArgumentList.Arguments.First().Expression); var repeatPattern = this.resolver.Resolve(patternName, this.pattern); foreach (var declaration in this.declarations) { callback( new AutomatedGenericStrategy( (IGenericDeclaration <SyntaxNode>)repeatPattern, (IGenericDeclaration <SyntaxNode>)declaration, this.resolver)); } }
private ISelector GetSelectorFromPatternAttribute(AttributeSyntax attributeSyntax) { var selectorExp = attributeSyntax.ArgumentList.Arguments.First(); var constEvaluator = new ConstantExpressionSyntaxEvaluator <string>(); var selectorTypeName = constEvaluator.Visit(selectorExp.Expression); var nsBase = this.pattern.UsingDirectives .Concat(NameSpaceHelper.GetParentNameSpaces(this.pattern.DeclarationNameSpace)); foreach (var usingDirective in nsBase) { var selectorType = Type.GetType($"{usingDirective}.{selectorTypeName}"); if (selectorType != null) { return((ISelector)Activator.CreateInstance(selectorType)); } } throw new ArgumentException($"Unknown selector {selectorTypeName}"); }
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); } }