How to get Type instance from IType (Resharper 8 SDK)

110 views Asked by At

I'm trying to write my first ReSharper extension and I'm stuck at the following problem:

How do you get a resolved Type from an IType descriptor of it?

For background, I'm trying to write an analyzer that uses a tool to test the compatibility of two type arguments.

So far, I've got this

[ElementProblemAnalyzer(new[] { typeof(IInvocationExpression) })]
public class MyAnalyzer : IElementProblemAnalyzer`
{
   public void Run(ITreeNode element, ElementProblemAnalyzerData analyzerData, IHighlightingConsumer consumer)
   {
        ...

        var typeArgs = meaningfulChildren.FirstOrDefault(o => o is ITypeArgumentList) as ITypeArgumentList;

        IType psiType = typeArgs.TypeArguments[0];
        Type actualType = psiType.ResolvedType; // No such property
   }
}
1

There are 1 answers

3
citizenmatt On BEST ANSWER

You can't do what you're asking for - ReSharper's type system is a view of the source of a project, not an assembly loaded into an AppDomain. In other words, you can get the IType for a class defined in Foo.cs, even if Foo.cs hasn't been loaded. It still needs to be able to return type information if the project can't compile, because the code in Bar.cs is just plain invalid.

So you can't convert an IType into a System.Type without compiling the project and loading the assembly into an AppDomain. But ReSharper has a lot of tools to work with types in its own view of the type system. What exactly are you trying to do?