I have the following C# code. For reasons I won\'t go into, this is the required way of localising.
My problem is, I cannot for the life of me figure out what path is no
Maybe you could refactor it so that at the bottom of your code you have a SINGLE return statement. And all your decision-making code simply 'sets' the return value.
Then in your switch(Name) block SET the value of what you want to return - then break out of the switch (rather than having a whole bunch of returns). IMO, this would make the code neater. Also, I think it'd make it easier to maintain.
ie.
switch(Name)
{
case "AppName": retString = ResMain.GetString("$this.Text");
case "MinimizeToTray": retString = "Closing the program minimizes it to the tray. To fully quit the program, right-click the icon in your tray and choose Exit.";
case "ReallyExit1": retString = "Do you really want to exit?";
case "ReallyExit2": retString = "Torrents will not be checked and downloaded until you launch the program again!";
default: retString = "String not found!";
}
...
return retString;
What is the purpose of the if-block? As far a I can see, if code below the switch is executed, StringNotFound
will always be true
so the if-block is not necessary, but it may very well confuse the code analysis.
To prevent mistakes or puzzles like this, you better not do both of this (below) , as there is no single logical flow anymore when you:
retVal
variable, together withreturn
statement.Choose one solution:
retVal
variable, or At the very end of your method, if StringNotFound
is false:
if(StringNotFound)
{
[...]
}
// missing return statement here
If StringNotFound is false, you don't return anything.
if(StringNotFound)
If this is false there is no else statment to catch it.
use
if(StringNotFound)
{
//your code
}
Else
{
return "String not found!";
}