Version Resources

I know that you can store localized versions of resources that will be retrieved by the application.

I would like to use a similar principle and store different versions of data in a resource file / assembly, and then use this version as a key to extract this data. Is it possible? Is this a common technique?

The data I will store is the UI Control identity.

So, for example, I would have several resources for each version:

Version 1.0 btnID = "thisButton1" Version 2.0 btnID = "thisButton2" 

The application will automatically determine which resource will be selected based on the version used.

+6
source share
1 answer

You can create your own class that will block access to resources and load the correct resource file inside. Assuming you have selected the name of the Resources.1.0.0.0.resources resource file, you can do the following:

  public class ResourceReader { private static ResourceManager _resourceManager = new ResourceManager( "Resources." + System.Reflection.Assembly .GetExecutingAssembly() .GetName() .Version.ToString(), Assembly.GetExecutingAssembly()); // If you have resource property btnID, you can expose it like this: public static string BtnID { get { return _resourceManager.GetString("btnID"); } } // you can add other properties for every value in the resource file. } 

All you have to do is find out the exact version of your application and ensure that such a resource file exists. This can be cumbersome if you enable automatic versioning in the assembly (for example, using 1.0. *). Of course, you can not use the entire version, but only major or major and minor version numbers.

+1
source

Source: https://habr.com/ru/post/903053/


All Articles