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


C# NamespaceDeclarationSyntax.WithUsings方法代码示例

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


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

示例1: VisitNamespaceDeclaration

        /// <summary>Called when the visitor visits a NamespaceDeclarationSyntax node.</summary>
        public override SyntaxNode VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
        {
            var u = _namespaces.Select(each => SyntaxFactory.UsingDirective(SyntaxFactory.ParseName($" {each}"))
                .WithLeadingTrivia(_leadingTrivia)
                .WithTrailingTrivia(_trailingTrivia)
            ).ToArray();

            node = node.AddUsings(u);
            node = node.WithUsings(Sort(node.Usings));
            return base.VisitNamespaceDeclaration(node);
        }
开发者ID:devigned,项目名称:autorest,代码行数:12,代码来源:AddUsingsRewriter.cs

示例2: AddUsing

		private static NamespaceDeclarationSyntax AddUsing(NamespaceDeclarationSyntax nspaceSyntax, UsingDirectiveSyntax newUsing)
		{
			if (nspaceSyntax.Usings.Count > 0)
			{
				var lastUsing = nspaceSyntax.Usings.Last();
				newUsing = newUsing
					.WithLeadingTrivia(lastUsing.GetLeadingTrivia())
					.WithTrailingTrivia(lastUsing.GetTrailingTrivia());

				return nspaceSyntax.WithUsings(nspaceSyntax.Usings.Add(newUsing));
			}

			return nspaceSyntax.WithUsings(nspaceSyntax.Usings.Add(newUsing.NormalizeWhitespace()));
		}
开发者ID:jackman0925,项目名称:StockSharp,代码行数:14,代码来源:MainWindow.xaml.cs

示例3: AmendUsings

		private static NamespaceDeclarationSyntax AmendUsings(NamespaceDeclarationSyntax nameSpace, SyntaxList<UsingDirectiveSyntax> usings)
		{
			var last = nameSpace.Name.ToString().Right(c => c != '.');
			
			foreach (var item in usings)
			{
				var name = item.Name.ToString();
				var first = name.Left(c => c != '.');

				if (first == last)
				{
					usings = usings.Remove(item);
					usings = usings.Add(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("global::" + name)));
				}
			}

			return nameSpace.WithUsings(usings);
		}
开发者ID:tumtumtum,项目名称:Shaolinq,代码行数:18,代码来源:Rewriter.cs


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