Resources 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.
Adding, editing, and removing resources
You can add, edit, and remove resources using the below functions:
AddResourceManager(): Adds a resource manager with a manager name for easier referenceEditResourceManager(): Edits a resource manager entry to contains a different resource managerRemoveResourceManager(): Removes a resource manager entry from the list
Querying resources
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 nameTryGetResourceManager(): Tries to get a resource manager from a manager nameResourceManagerExists(): Checks to see if a resource manager from a manager name exists
Once you get the resource manager instance, you can do whatever you want with it, referring to the documentation of the ResourceManager 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:
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.
You can see the full demonstration code by clicking the below button.
Last updated
