开发者

How to find the name of the default resources file in C# and VB.Net?

I've created an attribute, similar to the ToolboxBitmapAttribute, that allows you to associate an Icon or Image to a class.

To associate an image, the resource file base name, a type (to find the assembly), and the name of the resource are passed to the attribute constructor. I then use the ResourceManager to get access to the resource:

Dim rm = New ResourceManager(ResourceFileBaseName, passedType.Assembly)
Dim obj = rm.GetObject(resourceName)

This is fine except that I want the option to pass just the resource name in the constructor, and omit the resource file base name. Then I would pick up the resource from the def开发者_如何学Pythonault resource file. When I say default resource file, I mean the one when you start Visual Studio, open the property pages and click the Resources tab.

The problem is, when developing in VB.Net, the base name is 'RootNamespace.Resources', and when developing in C#, the base name is 'Rootnamespace.Properties.Resources'.

Where can I programatically find the name of the default resource file?

Update

What I can do is get a list of all resource names:

t.Module.Assembly.GetManifestResourceNames

I can then look for a name that ends with Resources.resources and use that to build the resource file base name.

This, however, is inefficient, but I suspect it's the only way to do it.


You could try all resource files in the assembly and test whether the icon is available.

It is going to very difficult to detect the default resource file. For example, I always move the resource files for my C# project to the root namespace. Also, the user may have purposefully put the image in a different resource file.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜