How do you determine the return type of a method using the ReSharper SDK?

207 views Asked by At

I'm trying to write a simple ReSharper 7.1 plugin to change the return type of methods under certain circumstances.

I've derived my class from ElementProblemAnalyzer<IMethodDeclaration> and implemented the Run method as follows:

    protected override void Run(IMethodDeclaration element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
    {
            consumer.AddHighlighting(new CustomHighlighting(element), element.TypeUsage.GetDocumentRange(), element.GetContainingFile());   
    }

That works well, inasmuch as it highlights the return type of every method. I can't seem to figure out how to check if the return type is void, nor can I change the method type from void to something else.

I see that the IMethodDeclaration interface has a TypeUsage, and that it's an instance of IPreDefinedType, which in turn implements IType, but the ReSharper SDK documentation doesn't explain how you can check the method's return type, nor how to change the return type.

1

There are 1 answers

0
kyano On

It's been a bit and I don't know if you are still looking for the answer. Others may find this helpful as well. You can use something like the following:

element.DeclaredElement.ReturnType.GetPresentableName(CSharpLanguage.Instance);

Unfortunately I don't quite know how to set the return type.