runtime icon indicating copy to clipboard operation
runtime copied to clipboard

How to get all keys in resourceManager?

Open Angelixion opened this issue 10 years ago • 11 comments

Before i could do something like this var result = resourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);

but now i cant find a way to get all keys in ResourceManager in RC2,

Thank you for your help.

Angelixion avatar May 27 '16 07:05 Angelixion

There is no single API that does this. Can you please elaborate your scenario so that we can think about adding a enumeration API.

For the time being you could look at using ResourceReader, a StreamingResourceManager example can be found in https://gist.github.com/ramarag/6e6f58a210dd00745582#file-streambasedresourcemanager-L34

ramarag avatar May 28 '16 00:05 ramarag

In RC1, System.Resources.ResourceManager, has a GetResourceSet, that it returns a ResourceSet with all the resources,

/// <summary>Retrieves the resource set for a particular culture.</summary>
    /// <returns>The resource set for the specified culture.</returns>
    /// <param name="culture">The culture whose resources are to be retrieved. </param>
    /// <param name="createIfNotExists">true to load the resource set, if it has not been loaded yet; otherwise, false. </param>
    /// <param name="tryParents">true to use resource fallback to load an appropriate resource if the resource set cannot be found; false to bypass the resource fallback process. (See the Remarks section.)</param>
    /// <exception cref="T:System.ArgumentNullException">The <paramref name="culture" /> parameter is null. </exception>
    /// <exception cref="T:System.Resources.MissingManifestResourceException">
    /// <paramref name="tryParents" /> is true, no usable set of resources has been found, and there are no default culture resources. </exception>
    [SecuritySafeCritical]
    [MethodImpl(MethodImplOptions.NoInlining)]
    public virtual ResourceSet GetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents);

But now i cant find a way to do the same in RC2

Angelixion avatar May 28 '16 09:05 Angelixion

Can you share your RC1 project. I believe this Api was unavailable even in RC1,unless you were building your application directly against mscorlib.dll or were using reflection

ramarag avatar May 31 '16 21:05 ramarag

I cannot share the project, but i used this (mscorlib) https://msdn.microsoft.com/en-us/library/system.resources.resourcemanager.getresourceset(v=vs.110).aspx

it worked for me in RC1 but now i cannot do it.

if it is not supported, it will be good to have a way to have a way to get a list with all the keys and values in the resource, and not only one.

Angelixion avatar Jun 03 '16 06:06 Angelixion

You are not supposed to build against mscolrib for .Net Core. As I mentioned above this scenario is not supported on .Net Core. But we should be happy to look into adding the capability if we get to know more about what you would like to do with the enumerated resources.

cc @tarekgh

ramarag avatar Jun 03 '16 18:06 ramarag

I use it to get a custom list of countries(and their code), and a custom list of languages(and their code) in a resx, it can be useful when you want to get a lot of resources, instead of going resource by resource, you can get all the resources and filter them in your own code if you need to, for example you will be able get all the resources and then filter the resources that contains in their value/key something without knowing the full names of the keys you want in your code. Sorry for my grammar.

Angelixion avatar Jun 06 '16 08:06 Angelixion

@ramarag is GetResourceSet going to get implemented? In my own case I want to be able to return all keys and values in resources file to the client for faster lookup.

yayadavid avatar Jul 26 '16 14:07 yayadavid

In my scenario we use(d) it to extract all available locals and 'exposed' it to clients (by means of fetching the list using an ajax request). Any alternatives that you can suggest?

mylemans avatar Jul 30 '16 13:07 mylemans

The old Resources APIs are getting added for netstandard2.0, which will solve this issue https://github.com/dotnet/corefx/issues/11769

ramarag avatar Sep 23 '16 22:09 ramarag

Has this option been added yet? I've created a new ASP.NET Core Web Application but it appears I can't use the ResourceManager.GetResourceSet command.

Sobiru avatar Jan 14 '17 00:01 Sobiru

I need this too. Analysis of which strings are and aren't actually used in our project. Because of the way our project is set up, checking references is not an option. We could parse the XML file manually, but this would be a lot smoother.

Legogris avatar Feb 23 '17 06:02 Legogris