当前位置: 首页>>代码示例>>C#>>正文


C# NamespaceDeclarationSyntax.GetLeadingTrivia方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.NamespaceDeclarationSyntax.GetLeadingTrivia方法的典型用法代码示例。如果您正苦于以下问题:C# NamespaceDeclarationSyntax.GetLeadingTrivia方法的具体用法?C# NamespaceDeclarationSyntax.GetLeadingTrivia怎么用?C# NamespaceDeclarationSyntax.GetLeadingTrivia使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.CSharp.Syntax.NamespaceDeclarationSyntax的用法示例。


在下文中一共展示了NamespaceDeclarationSyntax.GetLeadingTrivia方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateClasses

        public static MemberDeclarationSyntax[] GenerateClasses(NamespaceDeclarationSyntax @namespace)
        {
            var isInterfaceToClass = @namespace.GetLeadingTrivia().Any(trivia => trivia.ToString().Trim() == "//Meta(interface-to-class)");
            if (!isInterfaceToClass)
                return Array<MemberDeclarationSyntax>.Empty;

            var resultMembers = new List<MemberDeclarationSyntax>();
            foreach (var @interface in @namespace.Members.OfType<InterfaceDeclarationSyntax>())
            {
                resultMembers.Add(ToClass(@interface));
            }
            return resultMembers.ToArray();
        }
开发者ID:Serj-Tm,项目名称:NitroBolt.CodeGeneration,代码行数:13,代码来源:InterfaceToClassGenerator.cs

示例2: TraverseNamespace

        private Namespace TraverseNamespace(NamespaceDeclarationSyntax nds)
        {
            Namespace retNS = new Namespace();

            retNS.Name = nds.Name.ToString();

            if (nds.HasLeadingTrivia)
            {
                SetOuterComments(retNS, nds.GetLeadingTrivia().ToFullString());
            }

            if (nds.HasTrailingTrivia)
            {
                SetInnerComments(retNS, nds.GetTrailingTrivia().ToFullString());
            }

            //First, grab any objects defined at the beginning of the namespace (even delegates!)
            var delegates = from aDelegate in nds.ChildNodes().OfType<DelegateDeclarationSyntax>() select aDelegate;
            foreach (DelegateDeclarationSyntax dds in delegates)
            {
                //TraverseDelegate
            }

            //Next, traverse any classes
            var classes = from cls in nds.ChildNodes().OfType<ClassDeclarationSyntax>() select cls;
            foreach (ClassDeclarationSyntax cds in classes)
            {
                retNS.Classes.Add(TraverseClass(cds));
            }

            var interfaces = from anInterface in nds.ChildNodes().OfType<InterfaceDeclarationSyntax>() select anInterface;
            foreach (InterfaceDeclarationSyntax ids in interfaces)
            {
                Interface tempInterface = TraverseInterface(ids);
                retNS.Interfaces.Add(tempInterface);
            }
            var enums = from aEnum in nds.ChildNodes().OfType<EnumDeclarationSyntax>() select aEnum;
            foreach (EnumDeclarationSyntax eds in enums)
            {
                Model.Enum tempEnum = TraverseEnums(eds);
                retNS.Enums.Add(tempEnum);
            }
            //TODO: Don't forget enums
            return retNS;
        }
开发者ID:Zenoware,项目名称:RoslynParser,代码行数:45,代码来源:RoslynCSharpParser.cs


注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.NamespaceDeclarationSyntax.GetLeadingTrivia方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。