本文整理汇总了C#中Statement.GetPrevNode方法的典型用法代码示例。如果您正苦于以下问题:C# Statement.GetPrevNode方法的具体用法?C# Statement.GetPrevNode怎么用?C# Statement.GetPrevNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Statement
的用法示例。
在下文中一共展示了Statement.GetPrevNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddStatement
bool AddStatement(Statement statement)
{
if (reachability.IsReachable (statement))
return false;
if (collectedStatements.Contains (statement))
return true;
var prevEnd = statement.GetPrevNode ().EndLocation;
// group multiple continuous statements into one issue
var start = statement.StartLocation;
collectedStatements.Add (statement);
visitor.unreachableNodes.Add (statement);
while (statement.NextSibling is Statement) {
statement = (Statement)statement.NextSibling;
collectedStatements.Add (statement);
visitor.unreachableNodes.Add (statement);
}
var end = statement.EndLocation;
var removeAction = new CodeAction (visitor.ctx.TranslateString ("Remove unreachable code"),
script =>
{
var startOffset = script.GetCurrentOffset (prevEnd);
var endOffset = script.GetCurrentOffset (end);
script.RemoveText (startOffset, endOffset - startOffset);
});
var commentAction = new CodeAction (visitor.ctx.TranslateString ("Comment unreachable code"),
script =>
{
var startOffset = script.GetCurrentOffset (prevEnd);
script.InsertText (startOffset, Environment.NewLine + "/*");
var endOffset = script.GetCurrentOffset (end);
script.InsertText (endOffset, Environment.NewLine + "*/");
});
var actions = new [] { removeAction, commentAction };
visitor.AddIssue (start, end, visitor.ctx.TranslateString ("Code is unreachable"), actions);
return true;
}