I am trying to go over all pages and classes in my project to figure out where a method for my translations object is used, to get a translation by key. For example the localizer class looks something like this:
public class MyLocalizer {
public LocalizedString GetTranslation(string key){
//return localized string based on key
}
}
This is then injected and used on a razor page like this:
@inject MyLocalizer _localizer
<p>@_localizer.GetTranslation("foo")</p>
Or used on a PageModel like this:
private readonly MyLocalizer _localizer;
_localizer.GetTranslation("foo");
My goal is to find all references of GetTranslation and with which value it's called, so I can save this somewhere to give a translator some context when he is translating a string by linking the page where its used for example. Visual Studio already does this when right clicking the method and selecting "Find All References".
I have already experimented with the code shown in this answer, and it works, but does not consider razor pages. I am also struggling to apply this in a real situation, so using the current Workspace, Solution and project that i'm using. And also getting the text of all classes and razor pages to go over instead of just one hard coded class. I found that MSBuildWorkspace
could help with getting the current Solution and Workspace, but unfortunately that isn't added to .net core yet.
I'm hoping to get some pointers, tips or code examples of how to continue from here. I am new to using Roslyn, so any help would be greatly appreciated.