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


C# ArgumentSyntax.Ancestors方法代码示例

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


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

示例1: FormatXmlAsync

		private async Task<Document> FormatXmlAsync(Document document, ArgumentSyntax argSntax, CancellationToken cancellationToken)
		{
			var root = await document.GetSyntaxRootAsync(cancellationToken);
			var tree = root.SyntaxTree;

			//Get the character position of the ArgumentSyntax
			FileLinePositionSpan position = tree.GetLineSpan(argSntax.Span);
			int cSpace = position.StartLinePosition.Character;

			//Get the parent VariableDeclaration to figure out the preceeding trivia since we can't 
			//get the column position from GetLineSpan (bug?)
			var parent = argSntax.Ancestors().Where(t => t.IsKind(SyntaxKind.VariableDeclaration)).FirstOrDefault();
			var parentTrivia = parent.GetLeadingTrivia().ToFullString();

			var xml = argSntax.Expression.GetFirstToken().ValueText;
			var newXml = FormatXml(xml);

			//Process each line of the formatted XML and prepend the parent trivia & spaces
			string[] xmlLines = newXml.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
			for (int i = 1; i < xmlLines.Length; i++)
			{
				xmlLines[i] = parentTrivia + new String(' ', (cSpace - 14)) + xmlLines[i];
			}

			newXml = String.Join("\r\n", xmlLines);
			newXml = "@\"" + newXml + "\"";

			var newNode = SyntaxFactory.Argument(null, SyntaxFactory.Token(SyntaxKind.None), SyntaxFactory.IdentifierName(newXml));
			var newRoot = root.ReplaceNode(argSntax, newNode);
			return document.WithSyntaxRoot(newRoot);
		}
开发者ID:modulexcite,项目名称:GoingBeyondReSharperWithRoslyn_Demo,代码行数:31,代码来源:CodeRefactoringProvider.cs

示例2: FlowsOut

        private static bool FlowsOut(ExpressionSyntax dataFlowParent, ArgumentSyntax decl, IdentifierNameSyntax[] references)
        {
            ForStatementSyntax forStatement;

            if ((forStatement = decl.Ancestors().OfType<ForStatementSyntax>().FirstOrDefault()) != null &&
                 forStatement.Incrementors.Span.Contains(decl.Position) &&
                 forStatement.Statement.DescendantNodes().OfType<ForStatementSyntax>().Any(f => f.Condition == null))
            {
                return false;
            }

            var containingStatement = decl.Ancestors().OfType<StatementSyntax>().FirstOrDefault();
            var containingReturnOrThrow = containingStatement as ReturnStatementSyntax ?? (StatementSyntax)(containingStatement as ThrowStatementSyntax);

            MethodDeclarationSyntax methodDeclParent;

            if (containingReturnOrThrow != null && decl.Identifier.ValueText == "x1" && 
                ((methodDeclParent = containingReturnOrThrow.Parent.Parent as MethodDeclarationSyntax) == null ||
                  methodDeclParent.Body.Statements.First() != containingReturnOrThrow))
            {
                return false;
            }

            foreach (var reference in references)
            {
                if (!dataFlowParent.Span.Contains(reference.Span) && 
                    (containingReturnOrThrow == null || containingReturnOrThrow.Span.Contains(reference.SpanStart)) &&
                    (reference.SpanStart > decl.SpanStart || 
                     (containingReturnOrThrow == null &&
                     reference.Ancestors().OfType<DoStatementSyntax>().Join(
                         decl.Ancestors().OfType<DoStatementSyntax>(), d => d, d => d, (d1, d2) => true).Any())))
                {
                    if (IsRead(reference))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:vslsnap,项目名称:roslyn,代码行数:41,代码来源:OutVarTests.cs


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