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


C# ClassDeclarationSyntax.GetLeadingTrivia方法代码示例

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


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

示例1: TraverseClass

        public Class TraverseClass(ClassDeclarationSyntax cds)
        {
            Class retClass = new Class();
            //public List<Delegate> Delegates { get; set; }
            //public List<Method> FunctionDefs { get; set; }
            //public Inheritance Inheritance { get; set; }
            //public List<Module> Modules { get; set; }
            //public List<Preprocessor> Preprocessors { get; set; }
            //public List<Property> Properties { get; set; }
            //public List<Union> Unions { get; set; }
            retClass.Name = cds.Identifier.ValueText;
            if (cds.HasLeadingTrivia)
            {
                SetOuterComments(retClass, cds.GetLeadingTrivia().ToFullString());
            }

            if (cds.HasTrailingTrivia)
            {
                SetInnerComments(retClass, cds.GetTrailingTrivia().ToFullString());
            }
            foreach (SyntaxToken st in cds.Modifiers)
            {
                string modifier = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(st.ValueText);
                Encapsulation encap;
                Qualifiers qual;
                if (System.Enum.TryParse<Encapsulation>( modifier, out encap))
                {
                    retClass.Encapsulation.Add(encap);
                }
                else if (System.Enum.TryParse<Qualifiers>(modifier, out qual))
                {
                    retClass.Qualifiers.Add(qual);
                }
            }

            var enums = from aEnu in cds.ChildNodes().OfType<EnumDeclarationSyntax>() select aEnu;
            foreach (EnumDeclarationSyntax eds in enums)
            {
                retClass.Enums.Add(TraverseEnums(eds));
            }

            var structs = from aStruct in cds.ChildNodes().OfType<StructDeclarationSyntax>() select aStruct;
            foreach (StructDeclarationSyntax sds in structs)
            {
                retClass.Structs.Add(TransverseStructs(sds));
            }

            var methods = from aMethod in cds.ChildNodes().OfType<MethodDeclarationSyntax>() select aMethod;
            foreach (MethodDeclarationSyntax mds in methods)
            {
                retClass.Methods.Add(TransverseMethods(mds));
            }

            var Fields = from aField in cds.ChildNodes().OfType<FieldDeclarationSyntax>() select aField;
            foreach (FieldDeclarationSyntax fds in Fields)
            {
                retClass.Fields.Add(TransverseVariables(fds));
            }

            //var properties = from aProperty in cds.ChildNodes().OfType<PropertyDeclarationSyntax>() select aProperty;
            //foreach (PropertyDeclarationSyntax pds in properties)
            //{
            //    //traverse attributes
            //}

            var constructors = from aConstructor in cds.ChildNodes().OfType<ConstructorDeclarationSyntax>() select aConstructor;
            foreach (ConstructorDeclarationSyntax cods in constructors)
            {
                retClass.Constructors.Add(TransverseConstructors(cods));
            }

            var destructors = from aDestructor in cds.ChildNodes().OfType<DestructorDeclarationSyntax>() select aDestructor;
            foreach (DestructorDeclarationSyntax dds in destructors)
            {
                retClass.Destructors.Add(TransverseDestructors(dds));
            }

            var classes = from aClass in cds.ChildNodes().OfType<ClassDeclarationSyntax>() select aClass;
            foreach (ClassDeclarationSyntax cds2 in classes)
            {
                retClass.Classes.Add(TraverseClass(cds2));
            }

            return retClass;
        }
开发者ID:Zenoware,项目名称:RoslynParser,代码行数:85,代码来源:RoslynCSharpParser.cs


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