Example #1
0
        private static PropertyTemplate ParseProperty(SemanticModel semanticModel, PropertyDeclarationSyntax propertyDeclaration)
        {
            var matchOnCondition = new PropertyTemplateMatchCondition();

            var templateProperty = new PropertyTemplate
            {
                Name           = propertyDeclaration.Identifier.Text,
                MatchCondition = matchOnCondition
            };

            if (propertyDeclaration.ExpressionBody != null)
            {
                templateProperty.GetterBody = propertyDeclaration.ExpressionBody.Expression.ToString();
            }
            else
            {
                AccessorDeclarationSyntax getterAccessor = propertyDeclaration.AccessorList.Accessors.FirstOrDefault(acc => acc.Keyword.Text == "get");
                AccessorDeclarationSyntax setterAccessor = propertyDeclaration.AccessorList.Accessors.FirstOrDefault(acc => acc.Keyword.Text == "set");

                templateProperty.GetterBody = getterAccessor?.Body?.ToString();
                templateProperty.SetterBody = setterAccessor?.Body?.ToString();
            }

            return(templateProperty);
        }
Example #2
0
        private bool IsTypeMatch(PropertyTemplate template, string propertyType)
        {
            PropertyTemplateMatchCondition condition = template.MatchCondition;

            return(condition.PropertyTypeRule switch
            {
                PropertyTypeRule.Any => true,
                PropertyTypeRule.Specified => condition.Type == propertyType,
                _ => throw new NotImplementedException(condition.PropertyTypeRule.ToString())
            });