I have a Windows 8 app that I localize as described in the MSDN. My resource files use the default names ("Resources.resw") and locations ("Strings\en-US" etc.).
When I access the resources via ResourceLoader
, then ReSharper complains. Example:
private readonly ResourceLoader _resourceLoader = new ResourceLoader();
private void DoSomething()
{
string s = _resourceLoader.GetString("TestEntry");
}
ReSharper complains that I'm creating an ambiguous reference, because there are several "TestEntry" keys in several resource files. Duh. That's the whole point. The resource management should automatically use the correct resource, and it does indeed.
So, why does ReSharper complain? Is it a bug in ReSharper or is there really something wrong?
By the way: ReSharper recommends (among other fairly useless things) offers to put resource:
before the key string, like _resourceLoader.GetString(resource: "TestEntry")
(and then complains that it's redundant). This makes the ReSharper warning disappear. What does that do? Is it an improvement?
Edit: Oh my! I somehow thought resource:
is some special syntax, but it's just a named method argument...
Instead of constructing a new ResourceLoader, try using the static GetForCurrentView() method to retrieve the appropriate ResourceLoader.
private readonly ResourceLoader _resourceLoader = ResourceLoader.GetForCurrentView();
private void DoSomething()
{
string s = _resourceLoader.GetString("TestEntry");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With