TLDR;
I need to extract the string value of the parameter of all calls to the index operator of Microsoft.Extensions.Localization.IStringLocalizer
in my .NET code. Actually I also need the full name of the enclosing class.
Caveat: The above also includes my ASP.NET Core MVC razor views.
Basically my need is quite similar to the "Find all references" functionality in Visual Studio.
Why and other thoughts
The reason is that we appreciate the development flow using IStringLocalizer
without the need to actually create resources. In addition we have replaced the usage of resource files with a database store using Damien Bods AspNetCoreLocalization.
This allows us to have business experts do all the translations (1) without access to the file system of the webserver, and (2) from a nice interface that we provide, and (3) independently from the development cycle. However, in order to have the business experts know which texts exist - and thus need translation -
we need to extract all usages of the IStringLocalizer
(and IViewStringLocalizor
) index operator.
Based on this article, I've partly managed to extract the information from the loaded assemblies.
My major problems are:
- My code is based on SDILReader which is quite old and no longer maintained and apparently has a number of issues (with newer CIL?)
- How am I going to extract usage in razor views which are JIT compiled at runtime?
- I prefer to extract the data at latest at deployment time, but preferably at commit or CI build time
- Can Roslyn help fulfilling my need?
- Have I overlooked any tools or alternative approaches?
- I prefer a solution that isn't to vulnerable to future .NET framework/runtimes versions or new C# features
Any ideas or pointers are most welcome :-) Thanks