Reputation: 33
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 requirement for a change in the class inheritance hierarchy. I need to change the top base class of certain inheritance chains from System.Object
to System.MarshalByRefObject
.
The problem is that the reasoning of whether the change is needed down in one of the subclasses. The AnalyzeSymbol
method, is passed SymbolAnalysisContext
that points to one subclass, but the codefix is needed elsewhere.
I tried to pass the location of the baseclass declaration as AdditionalLocations
property to the Diagnostic
that I report. This works, sort of. I am able to retrieve this location on the CodeFixProvider
side, but only if the location is in the same project. If the Declaration of the baseclass is in different project, as most of the time it is, the AdditionalLocations
property is empty.
Example in code:
Derived class is flagged by the analyzer, here the dummy reason is the interface IVisible
.
// Project A
class BaseClass
{
...
}
// Project B
class DerivedClass : BaseClass, API.IVisible
{
...
}
The expected codefix is this:
// Project A
class BaseClass : System.MarshalByRefObject
{
...
}
// Project B
class DerivedClass : BaseClass, API.IVisible
{
...
}
What is the correct way to point to a different context for the CodeFixProvider
? Is there a better way to do this sort of refactoring?
Upvotes: 1
Views: 161