列出当前项目中的资源

发布于 2024-12-01 22:22:35 字数 213 浏览 3 评论 0原文

从 UITypeEditor 加载的表单中,如何获取当前项目中的资源列表?

我尝试过使用 GetManifestResourceNames() ,但这为我提供了创建用户控件的项目的资源列表,而不是我使用的投影中的资源列表 用户控件。

我猜我需要能够获取根容器所在项目的程序集名称,以便我可以创建正确的资源管理器?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

聆听风音 2024-12-08 22:22:35

如果您想获取给定实例的类所属的程序集,请尝试以下操作

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

如果您知道类型,只需执行此操作

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

或者,您可以在用户控件中尝试此操作

 Assembly a = Assembly.GetCallingAssembly();

最后一个示例将返回方法的程序集调用当前正在执行的方法。也许您可以将程序集引用存储为用户控件中的成员变量,并在用户控件的构造函数中分配它。这将为您提供对实例化 UserControl 的程序集的引用

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

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