Search code examples
c#.netroslyncompiler-warnings

How to use internal Roslyn classes?


What is correct way for using Roslyn API in analysers? Let say I need to fetch info from context.Symbol and it is a field. So it is obvious I can cast it to IFieldSymbol but I need to check initializer text. How I can get properties of underlying SourceFieldSymbol? It is Internal!

Reflection ? ;))))


Solution

  • Don't do that.
    Roslyn has a well-design public API which should be able to do anything you need (except at the editor level).

    In this particular case, you should use the DeclaringSyntaxReferences property.

    In general, you can use http://sourceroslyn.io/ to follow the tree of references to an internal property and find the public API.