gitlabEdit

filesResources Manager

How do we manage our resources?

ResourceLab is a small library that contains a single class that is dedicated to managing the resources from different assemblies. This facility is achieved via a single class called ResourcesManager.


What is ResourcesManager?

ResourcesManager contains a static list of resources that are shared across assemblies that it manages. Users of the library can use it to add their own resource manager for their assembly or other assemblies to this list.

This class contains a static property that returns a list of resource managers, called ResourceManagers, that returns a list of resource managers by their tagged names.

chevron-rightAdding, editing, and removing resourceshashtag

You can add, edit, and remove resources using the below functions:

  • AddResourceManager(): Adds a resource manager with a manager name for easier reference

  • EditResourceManager(): Edits a resource manager entry to contains a different resource manager

  • RemoveResourceManager(): Removes a resource manager entry from the list

chevron-rightQuerying resourceshashtag

Other applications and libraries can get those newly-created resources and query them using the following functions:

  • GetResourceManager(): Gets a resource manager from a manager name

  • TryGetResourceManager(): Tries to get a resource manager from a manager name

  • ResourceManagerExists(): Checks to see if a resource manager from a manager name exists

circle-info

Once you get the resource manager instance, you can do whatever you want with it, referring to the documentation of the ResourceManagerarrow-up-right class.


Example (three libraries and one app)

In this example, we're going to use ResourceLab to make this application get resources from three libraries using a single ResourcesManager static class. The three libraries' names will be ResDemo1, ResDemo2, and ResDemo3, and the demo app name will be ResourceLab.Demo. Follow the below steps:

1

Installing the resources

Install the resources you want (.resx files) to all three libraries, such as Resources/Demonstration.resx.

2

Installing ResourceLab

Install ResourceLab to both the three libraries and the ResourceLab.Demo app.

3

Define a public function in libraries

In each library source code, define a public function, AddResource(), to use the two functions to install a resource manager to the static list of resource managers.

For example, we'll install a string resource from the first library to the list of resource managers.

Then, we'll install a binary resource from the second library to the list of resource managers.

Finally, we'll install a string resource that gets localized according to the current UI culture from the third library to the list of resource managers.

4

Make an application refer to the three libraries

After that, add references to the three libraries in the application project.

5

Make the application query the resources

Add the following code, assuming that Terminaux has been installed to the demo app:

6

Verify the output

If everything is OK, you should see the below output:

You can see the full demonstration code by clicking the below button.

See full demo code here

Last updated