本文整理汇总了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();
}
示例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;
}