M
M
Maxim2019-08-13 18:00:16
.NET
Maxim, 2019-08-13 18:00:16

How to get .net resources in assembly?

How to get resources(resx) of .net program?
I am developing a library that should receive the resources of the assembly that calls it. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Makarov, 2019-08-14
@Got_Oxidus

You can start with this:

IEnumerable<object> GetResources(System.Reflection.Assembly inAssembly, System.Globalization.CultureInfo inCultureInfo) =>
            ((System.Resources.ResourceManager)inAssembly
                .GetTypes()
                .FirstOrDefault(type => type.Name == "Resources")
                .GetProperty("ResourceManager", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)
                .GetValue(null, null))
                    .GetResourceSet(inCultureInfo, true, true)
                    .OfType<System.Collections.DictionaryEntry>()
                    .Select(item => item.Value);


var resources = GetResources(System.Reflection.Assembly.GetCallingAssembly(), System.Globalization.CultureInfo.InvariantCulture);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question