检索程序集中的所有 ResourceManager
为了在 Wpf 中进行本地化,我想循环遍历程序集中的所有 ResourceManager。
我想这样做的原因是我有一个翻译 xaml 标记扩展。此标记扩展需要使用完全限定的命名空间和程序集名称来实例化 ResourceManager。
默认程序集是 xaml 文件所在的程序集,可以按如下方式检索:
var rootObjectProvider = serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;
var root = rootObjectProvider.RootObject;
var assembly = ass = Assembly.GetAssembly(root.GetType());
当给定相对路径时,需要在前面添加默认路径,但这是 VS 的东西而不是程序集的东西。大多数程序集的名称与默认命名空间相同,但情况并非总是如此。因此,我想循环遍历程序集中的所有 ResourceManager,并尝试将其命名空间的最后部分与为标记扩展提供的字典路径进行匹配。
For localization purposes in Wpf I would like to loop through all ResourceManagers in an assembly.
The reason I want to do this is that I have a translate xaml markup extension. This markup extension needs to instantiate a ResourceManager using a fully qualified namespace and an assembly name.
The default assembly is the assembly in which the xaml file is located in which can be retrieved as follows:
var rootObjectProvider = serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;
var root = rootObjectProvider.RootObject;
var assembly = ass = Assembly.GetAssembly(root.GetType());
When given a relative path the default path needs to be prepended, but this is a VS thing not an assembly thing. Most assemblies have the same name as the default namespace, but this is not always the case. Therefor I would like to loop through all ResourceManagers in an Assembly and try to match the last part of their namespace with the dictionary path given to the markup extension.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我找到了如何做到这一点:
不过,该操作似乎相当昂贵,下一个挑战:在 ResourceDictionary 中加载 ResourceManager ..
Okay I found out how to do it:
The operation seems quite costly though, next challenge: loading a ResourceManager in a ResourceDictionary..