Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ReSharper complain about this use of ResourceLoader.GetString?

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.).

enter image description here

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");
}

enter image description here

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...

like image 966
Sebastian Negraszus Avatar asked Jul 04 '13 14:07

Sebastian Negraszus


1 Answers

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");
}
like image 104
Peter Pompeii Avatar answered Oct 15 '22 01:10

Peter Pompeii