private static IFieldSymbol GetBackingFieldFromGetter(
            AccessorDeclarationSyntax getter,
            SemanticModel semanticModel)
        {
            // The getter should have a body containing a single return of a backing field.

            if (getter.Body == null)
            {
                return(null);
            }

            SyntaxList <StatementSyntax> statements = getter.Body.Statements;

            if (statements.Count != 1)
            {
                return(null);
            }

            if (!(statements.Single() is ReturnStatementSyntax returnStatement) || returnStatement.Expression == null)
            {
                return(null);
            }

            return(semanticModel.GetSymbolInfo(returnStatement.Expression).Symbol as IFieldSymbol);
        }
Example #2
0
        private static string GetDescriptionContent(SyntaxList <AttributeListSyntax> list)
        {
            var singleAttribute      = list.Single();
            var descriptionAttribute = singleAttribute.Attributes.Single();
            var descriptionContent   = descriptionAttribute.ArgumentList.Arguments.Single().ToString();

            return(descriptionContent.Trim('"'));
        }
Example #3
0
        public static SyntaxList <T> WithCsSourceMappingFrom <T>(this SyntaxList <T> converted, SyntaxNode node) where T : VisualBasicSyntaxNode
        {
            if (converted.Count != 1)
            {
                return(WithSourceMappingFrom(converted, node));
            }
            var single = converted.Single();

            return(converted.Replace(single, single.WithCsSourceMappingFrom(node)));
        }
Example #4
0
        private ClassDeclarationSyntax WrapMembersWithComment(ClassDeclarationSyntax node, SyntaxList <MemberDeclarationSyntax> members)
        {
            if (members.Count == 0)
            {
                node = node.WithOpenBraceToken(GetOpenBraceTokenWithEmptyCustomCode())
                       .WithMembers(SyntaxFactory.List <MemberDeclarationSyntax>());
            }
            else if (members.Count == 1)
            {
                var newMember = AddLeadingTriviaComment(AddTrailingTriviaComment(members.Single()));
                node = node.WithMembers(members.RemoveAt(0).Add(newMember));
            }
            else
            {
                var firstMember = AddLeadingTriviaComment(members.First());

                var lastMember    = AddTrailingTriviaComment(members.Last());
                var lastMemberIdx = members.Count - 1;

                node = node.WithMembers(members.RemoveAt(lastMemberIdx).RemoveAt(0).Insert(0, firstMember).Add(lastMember));
            }

            return(node);
        }
Example #5
0
 public static TSyntax FindByName <TSyntax>(
     this SyntaxList <TSyntax> list,
     Func <TSyntax, SyntaxNode> accessor,
     string value) where TSyntax : SyntaxNode
 => list.Single(t => accessor(t).ToString() == value);