首页 \ 问答 \ Roslyn:诊断中的当前工作空间,带有代码修复项目(Roslyn: Current Workspace in Diagnostic with code fix project)

Roslyn:诊断中的当前工作空间,带有代码修复项目(Roslyn: Current Workspace in Diagnostic with code fix project)

如何通过代码修复项目获取Diagnostic中当前Workspace的信息(例如项目路径,解决方案路径)?

我正在实现类型ISyntaxNodeAnalyzer的Diagnostic

我需要访问SymbolFinder.FindImplementationsAsync,但为了这样做,我需要Solution实例

编辑:我有这样的代码:

var syntax = (LocalDeclarationStatementSyntax) node;
var type = syntax.Declaration.Type;
var typeSymbol = semanticModel.GetTypeInfo(type).ConvertedType;

我想找出typeSymbol的所有用法/参考。 TypeSymbol表示位于源代码中的Class。

为此,我想使用SymbolFinder,但是SymbolFinder的方法需要Solution的实例...在旧版本的Roslyn中,Document作为诊断的方法参数给出,您可以进入项目和解决方案。


How can I get information about current Workspace (e.g project path, solution path) in Diagnostic with code fix project?

I am implementing Diagnostic of type ISyntaxNodeAnalyzer

I need to access SymbolFinder.FindImplementationsAsync, but to do so, I need Solution instance

EDIT: I have code like this:

var syntax = (LocalDeclarationStatementSyntax) node;
var type = syntax.Declaration.Type;
var typeSymbol = semanticModel.GetTypeInfo(type).ConvertedType;

I would like to find out all usages / references of typeSymbol. TypeSymbol represents Class located in source code.

To do so, I wanted to use SymbolFinder, but methods of SymbolFinder require instance of Solution... In older version of Roslyn, Document was given as Method Parameter of diagnostics, you could get to project and solution.


原文:https://stackoverflow.com/questions/23203206
更新时间:2024-03-04 08:03

最满意答案

将该循环的大小移出外循环:

void delete_repeats(char array[],int size){
  for(int i = 0; i < size; i++){
    for(int j = i + 1; j < size; j++){
        if(array[i] == array[j] || !((array[j] >= 97) && (array[j] <= 122))){
            for(int k = j; k < size; k++){
                array[k] = array[k + 1];
            }
            size--;
        }

    }
  }
}

INPUT: Mary had a little lamb
OUTPUT:  Maryhdlitemb


Move the size out of that loop into the outer loop:

void delete_repeats(char array[],int size){
  for(int i = 0; i < size; i++){
    for(int j = i + 1; j < size; j++){
        if(array[i] == array[j] || !((array[j] >= 97) && (array[j] <= 122))){
            for(int k = j; k < size; k++){
                array[k] = array[k + 1];
            }
            size--;
        }

    }
  }
}

INPUT: Mary had a little lamb
OUTPUT:  Maryhdlitemb

相关问答

更多