我知道可以存储要由应用程序检索的本地化资源版本.
我想使用类似的原则并将不同版本的数据存储到资源文件/程序集中,然后使用该版本作为密钥来检索此数据.这可能吗?这是一种常见的技术吗?
我将存储的数据是UI控制数据标识.
例如,我会为每个版本提供多个资源:
Version 1.0 btnID = "thisButton1"
Version 2.0 btnID = "thisButton2"
Run Code Online (Sandbox Code Playgroud)
应用程序将根据当前使用的版本自动确定要拾取的资源.
您可以创建一个自定义类,它将包装对资源的访问并在内部加载正确的资源文件。假设您已选择命名资源文件Resources.1.0.0.0.resources,您可以执行以下操作:
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.
}
Run Code Online (Sandbox Code Playgroud)
您需要做的就是了解应用程序的确切版本并确保此类资源文件存在。如果您在程序集信息中启用了自动版本控制(例如使用 1.0.*),这可能会很麻烦。当然,您可以选择不使用整个版本,而仅使用主要或主要和次要版本号。