Пример #1
0
        protected override BaseTypeDeclarationSyntax GetTypeDeclarationSyntax()
        {
            var hasAttributes = AttributeListCollection != null;
            var hasModifiers  = ModifierList != null;
            var declaration   = StructDeclaration(
                Identifier.GetSyntaxToken((!hasAttributes && !hasModifiers) ? DocumentationCommentList : null));

            if (hasAttributes)
            {
                declaration = declaration.WithAttributeLists(
                    AttributeListCollection.GetAttributeListSyntaxList(DocumentationCommentList));
            }
            if (hasModifiers)
            {
                declaration = declaration.WithModifiers(
                    ModifierList.GetSyntaxTokenList(hasAttributes ? null : DocumentationCommentList));
            }
            if (BaseList != null)
            {
                declaration = declaration.WithBaseList(
                    BaseList.GetBaseListSyntax());
            }
            if (ConstraintClauseList != null)
            {
                declaration = declaration.WithConstraintClauses(
                    ConstraintClauseList.GetConstraintClauses());
            }
            if (TypeParameterList != null)
            {
                declaration = declaration.WithTypeParameterList(
                    TypeParameterList.GetTypeParameterListSyntax());
            }
            // Get members
            var memberList = new List <MemberDeclarationSyntax>();

            if (FieldList != null)
            {
                memberList.AddRange(FieldList.GetMemberDeclarationSyntax());
            }
            if (ConstructorList != null)
            {
                memberList.AddRange(ConstructorList.GetMemberDeclarationSyntax());
            }
            if (PropertyList != null)
            {
                memberList.AddRange(PropertyList.GetMemberDeclarationSyntax());
            }
            if (MethodList != null)
            {
                memberList.AddRange(MethodList.GetMemberDeclarationSyntax());
            }
            return(memberList.Count == 1
                ? declaration.WithMembers(
                       SingletonList(memberList.First()))
                : declaration.WithMembers(
                       List(memberList)));
        }
Пример #2
0
        public MemberDeclarationSyntax GetMemberDeclarationSyntax()
        {
            var hasAttributes = AttributeListCollection != null;
            var hasModifiers  = ModifierList != null;
            var declaration   = MethodDeclaration(
                IdentifierName(
                    Type.GetSyntaxToken((!hasAttributes && !hasModifiers) ? DocumentationCommentList : null)),
                Identifier.GetSyntaxToken());

            if (hasAttributes)
            {
                declaration = declaration.WithAttributeLists(
                    AttributeListCollection.GetAttributeListSyntaxList(DocumentationCommentList));
            }
            if (hasModifiers)
            {
                declaration = declaration.WithModifiers(
                    ModifierList.GetSyntaxTokenList(hasAttributes ? null : DocumentationCommentList));
            }
            if (ParameterList != null)
            {
                declaration = declaration.WithParameterList(
                    ParameterList.GetParameterListSyntax());
            }
            if (TypeParameterList != null)
            {
                declaration = declaration.WithTypeParameterList(
                    TypeParameterList.GetTypeParameterListSyntax());
            }
            return((ArrowClauseExpressionValue != null)
                ? declaration
                   .WithExpressionBody(
                       ArrowExpressionClause(
                           ArrowClauseExpressionValue.GetExpressionSyntax()))
                   .WithSemicolonToken(
                       Token(SyntaxKind.SemicolonToken))
                : (Block != null)
                ? declaration.WithBody(
                       Block.GetBlockSyntax())
                : declaration.WithSemicolonToken(
                       Token(SyntaxKind.SemicolonToken)));
        }