开发者

List resources in the current project

开发者 https://www.devze.com 2023-03-31 12:03 出处:网络
From a form loaded from a UITypeEditor, how do I get a list of resources in the current project? I\'ve tried using GetManifestResourceNames() but that gives me a list of resources for the project the

From a form loaded from a UITypeEditor, how do I get a list of resources in the current project?

I've tried using GetManifestResourceNames() but that gives me a list of resources for the project the user control was created in, instead of the a list of resources in the projected I'm using the开发者_Python百科 user control in.

I'm guessing I need to be able to get the the assembly name of the project in which the root container resides so that I can create the correct resource manager?


If you want to get the assembly that a class of a given instance belongs to, try the following

 Assembly a = Assembly.GetAssembly(instance.GetType());

If you know the type, simply do this

 Assembly a = Assembly.GetAssembly(typeof(MyUserControl));

Or, you can try this, in your user control

 Assembly a = Assembly.GetCallingAssembly();

The last example will return the Assembly of the method that invoked the currently executing method. Perhaps you could store an Assembly reference as a member variable in your UserControl and assign it in your UserControl's constructor. That would give you a reference to the assembly that instantiates your UserControl

0

精彩评论

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

关注公众号