开发者

Retrieve all ResourceManagers in an assembly

For localization 开发者_如何学Gopurposes 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.


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..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜