Is there a way to loop through all the resources in a .resx
file in C#?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
If you want to use LINQ, use
resourceSet.OfType<DictionaryEntry>()
. Using LINQ allows you, for example, to select resources based on their index (int) instead of key (string):Using LINQ to SQL:
The minute you add a resource .RESX file to your project, Visual Studio will create a Designer.cs with the same name, creating a a class for you with all the items of the resource as static properties. You can see all the names of the resource when you type the dot in the editor after you type the name of the resource file.
Alternatively, you can use reflection to loop through these names.
This method is obviously only usable when the RESX file is in scope of the current assembly or project. Otherwise, use the method provided by "pulse".
The advantage of this method is that you call the actual properties that have been provided for you, taking into account any localization if you wish. However, it is rather redundant, as normally you should use the type safe direct method of calling the properties of your resources.
see link: microsoft example
Blogged about it on my blog :) Short version is, to find the full names of the resources(unless you already know them):
To use all of them for something:
To use resources in other assemblies than the executing one, you'd just get a different assembly object by using some of the other static methods of the
Assembly
class. Hope it helps :)You should always use the resource manager and not read files directly to ensure globalization is taken into account.