Questions tagged [codefixprovider]
21 questions
4
votes
1 answer
How to get statements for IMethodSymbol?
I'm working on the Code Fix provider for .Net.
I'd like to check method internals, e.g. method statements from IMethodSymbol.
As an example, I have following code on input:
public void DoSomething(string input)
{
if(input == null)
throw…

Manushin Igor
- 3,398
- 1
- 26
- 40
3
votes
1 answer
How to convert an IMethodSymbol to a MethodDeclarationSyntax?
Given an IMethodSymbol how can I create a MethodDeclarationSyntax?
Background:
For a code fix, I'm copying methods from one class which implements an interface into another which implements a different one.
As a result, I need to modify a few things…

Rolan
- 2,924
- 7
- 34
- 46
3
votes
2 answers
How do I debug a CodeFixProvider not ever loading
I have made a new "Analyzer with Code Fix (.NET Standard)" project, and updated the analyzer to check for what I want, and that works great. Now I have modified the CodeFixProvider, but it never shows up when debugging.
I have set breakpoints in the…

Jeremy Morton
- 375
- 2
- 13
3
votes
1 answer
Roslyn CodeFixProvider isn't loading or running in the Visual Studio IDE. What am I missing?
I first wrote a DiagnosticAnalyzer and then battled to get it to load until I listed its project as an Asset in the VSIX manifest.
Now I also added a CodeFixProvider to the same project as the analyzer, but it doesn't load.
What am I missing?
I…

Martin Lottering
- 1,624
- 19
- 31
2
votes
0 answers
Analyzer + Code Fix not generating option
I have an analyzer & Code fix that I want to make into a nuget package.
When I run this analyzer using the .VSIX project, the Analyzer highlights the correct option but the code fix does not show up when I look at the options (also occurs if I…

Rolan
- 2,924
- 7
- 34
- 46
2
votes
1 answer
How to provide fix for all parameters of the method (Roslyn - FixProvider)
I wrote code analyzer & fix provider for adding validations to ensure argument is not null. It works good for multiple methods, but I cannot check all the parameters at once. The analyzer will mark all the parameters that are not checked already,…

Divisadero
- 895
- 5
- 18
2
votes
1 answer
Code fix : change members and class being used for a method call
I am doing a code analyser but I can't find a way to change the class and the members being accessed when you are calling a method. For example if i have
public class FirstClass
{
public static void DoSomething(object SomeParameter)
{
…

nalka
- 1,894
- 11
- 26
2
votes
0 answers
SyntaxNode ReplaceNode doesn't replace node
I'm trying to replace a statement in code with something else entirely. From:
var results = item.Axes.GetDescendants();
To (something like):
using (var context = ContentSearchManager.GetIndex("someindex").CreateSearchContext())
{
…

Trayek
- 4,410
- 3
- 24
- 39
1
vote
0 answers
Unexpected line breaks with Roslyn C# CodeFixProvider and Trivia
I am currently trying to write a C# CodeFixProvider which is supposed to replace calls to setXXX() methods with property setter access if a corresponding property exists.
Basically
setSimpleProperty(42);
is replaced with
SimpleProperty = 42;
The…

user1211286
- 681
- 5
- 17
1
vote
0 answers
Roslyn: How to make codefix on context in different project?
I am trying to write a proprietary analyzer and codefix for the following problem. Bare in mind this is my first time using Roslyn APIs. I'll gladly accept any general tips and advice.
There is a huge code base with thousands of classes and a…

Venca.M
- 33
- 1
- 6
1
vote
1 answer
Roslyn CodeFix Provider (VS2015): How to get a class property/field type
How can I get the data type of a property/field?
The only way that I'm able to do that is by searching in the syntax tree of the document where the class is stored. It's a bit slow and there's also the problem of inheritance (Need's to search other…

João Miguel Soares
- 56
- 6
1
vote
1 answer
Roslyn CodeFixProvider: Move caret after applying code fix
i have implemented a custom CodeFixProvider that adds some XML documentation to members.
Example:
public void MyMethod() { }
will be transformed to
///
public void MyMethod() { }
The CodeFixProvider is implemented like…

fss
- 113
- 1
- 5
1
vote
0 answers
Roslyn CodeFix: Create a Document
I'm playing with Roslyn analyzers and Codefixes. In my scenario I wan't to have every domain class should have an according builder in another project.
The diagnostic part was no problem but now I struggle with the codefix.
That is what I have so…

Tobias
- 2,945
- 5
- 41
- 59
1
vote
0 answers
Roslyn Analyzer Select Document Changes
I'm trying to figure out how I can select Individual changes for updating issues in a document. When you select a code action to fix an issue. There are 3 additional options fix for document/project/solution:
The window reflect the full change…

johnny 5
- 19,893
- 50
- 121
- 195
1
vote
1 answer
Replacing string literals with private const statements
I'm building an analyzer for C# code which generates errors when a string literal is used instead of a const string for certain arguments for certain functions. Ie.
class MyClass
{
private void MyMethod(IWriter writer)
{
…

David Rutten
- 4,716
- 6
- 43
- 72