SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Get from TypeReferenceExpression to TypeDeclaration?

Last post 03-25-2015 10:02 PM by Piedone. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 03-24-2015 12:29 AM

    Get from TypeReferenceExpression to TypeDeclaration?

    I'm using ICSharpCode.Decompiler.Ast.AstBuilder (which is used by SharpDevelop, NRefactory and ILSpy under the hood; has taken inspiration from there too) from code to build an abstract syntax tree from a .NET Common Intermediate Language assembly.

    var assembly = AssemblyDefinition.ReadAssembly(assemblyPath);
    var astBuilder = new AstBuilder(new DecompilerContext(assembly.MainModule));
    // astBuilder.SyntaxTree ...

    The syntax tree contains TypeReferenceExpressions whenever a line like Math.Abs() is there. How can I retrieve the TypeDeclaration of the referenced type when it also exists in the same syntax tree?

    The closest I got is TypeReferenceExpression.Type.ToTypeReference().Resolve() but this is very heavy to orchestrate, and I already have (I suppose) all the information in the syntax tree. I also tried manual lookup by using namespaces an identifiers but I guess there should be a better way.

    I cross-posted this from StackOverflow but figured it's better here.

  • 03-25-2015 10:02 PM In reply to

    Re: Get from TypeReferenceExpression to TypeDeclaration?

    Mike Strobel replied on SO.

Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this ( email address.