Пример #1
0
        public override IEnumerable <SyntaxNode> BuildSyntax(IDom item)
        {
            var itemAsT = item as IClass;

            Guardian.Assert.IsNotNull(itemAsT, nameof(itemAsT));

            var modifiers = item.BuildModfierSyntax();

            if (itemAsT.IsAbstract)
            {
                modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.AbstractKeyword));
            }
            if (itemAsT.IsSealed)
            {
                modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.SealedKeyword));
            }
            if (itemAsT.IsPartial)
            {
                modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.PartialKeyword));
            }
            var identifier = SyntaxFactory.Identifier(itemAsT.Name);

            var node = SyntaxFactory.ClassDeclaration(identifier)
                       .WithModifiers(modifiers);

            node = BuildSyntaxHelpers.AttachWhitespace(node, item.Whitespace2Set, whitespaceLookup);

            var baseList = BuildSyntaxHelpers.GetBaseList(itemAsT);

            if (baseList != null)
            {
                node = node.WithBaseList(baseList);
            }

            var attributes = BuildSyntaxWorker.BuildAttributeSyntax(itemAsT.Attributes);

            if (attributes.Any())
            {
                node = node.WithAttributeLists(BuildSyntaxHelpers.WrapInAttributeList(attributes));
            }

            var membersSyntax = itemAsT.Members
                                .SelectMany(x => RDom.CSharp.GetSyntaxGroup(x))
                                .ToList();

            node = node.WithMembers(SyntaxFactory.List(membersSyntax));

            node = BuildSyntaxHelpers.BuildTypeParameterSyntax(
                itemAsT, node, whitespaceLookup,
                (x, p) => x.WithTypeParameterList(p),
                (x, c) => x.WithConstraintClauses(c));

            return(node.PrepareForBuildSyntaxOutput(item, OutputContext));
        }