Hi all,
Can someone just give me a dead-simple example of how to find, read,
and use resource files from C# using the VS2005 IDE?
I need to call some strings from a resource file and am having a
hard time understanding how to use ResourceManager. I can find
examples of how to create resource files, but not how to reference them
from C# code. Could somebody please point me to a simple example?
I've tried both using the ResXFile Code generator and tried creating a
resource file from scratch but I keep getting
MissingManifestResourceException. The example below is the best I can
find but it is not clear what the name of the resource file is, where
is it located, and how do I tell VS to include it:
So my question is: using the example below
1)what is the NAME of the resource file expected?
2)where is it placed? How does VS know where it is located?
3) Is there a dead-simple way to do this?
using System;
using System.Globalization;
using System.Reflection;
using System.Resources;
[assembly: NeutralResourcesLanguageAttribute("en-US")]//what does this
do?
//and how are we telling VS what and where our
resourcefiles are?
namespace GlobalizationLibrary
{
public class DoNotPassLiterals
{
ResourceManager stringManager;
public DoNotPassLiterals()
{
stringManager =
new ResourceManager("en-US",
Assembly.GetExecutingAssembly());
}//if I create en-US.resources file in resources directory it
still doesn't find it
public void TimeMethod(int hour, int minute)
{
if(hour < 0 || hour 23)
{
throw new ArgumentOutOfRangeException(
"hour", hour,
"The valid range is 0 - 23.");
}
if(minute < 0 || minute 59)
{
throw new ArgumentOutOfRangeException(
"minute", minute,
stringManager.GetString(
"minuteOutOfRangeMessage",
CultureInfo.CurrentUICulture));
}
}
}