检索程序集中的所有 ResourceManager

发布于 2024-10-08 01:51:42 字数 548 浏览 2 评论 0原文

为了在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

俏︾媚 2024-10-15 01:51:43

好吧,我找到了如何做到这一点:

var resources = assembly.GetManifestResourceNames();

不过,该操作似乎相当昂贵,下一个挑战:在 ResourceDictionary 中加载 ResourceManager ..

Okay I found out how to do it:

var resources = assembly.GetManifestResourceNames();

The operation seems quite costly though, next challenge: loading a ResourceManager in a ResourceDictionary..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文