我可以将图像与类关联并加载该图像而不创建该类的实例吗?
潜伏已久,第一次在这里发帖。
我的问题是:
使用 C# 2.0,有没有一种方法可以将图像与类/类型相关联,这样我就不必创建该类的实例来从该类获取图像对象?
我想做的是扫描应用程序中的所有 .dll 并构建类和相应属性的列表。我的工作很好,现在我想以某种方式将图像与每个类相关联,以便我可以显示类列表并为每个类提供唯一的图像。
我尝试在 SO 和互联网上搜索答案,但找不到任何明确的东西。任何帮助将不胜感激。
谢谢,
凯尔
Long time lurker, first time poster here.
My question is:
Using C# 2.0, is there a way to associate am image with a class/type such that I don't have to create an instance of the class just to get the image object from that class?
What I am trying to do is scan all the .dlls in my application and construct a list of classes and corresponding attributes. I have this working great, and now I want to somehow associate an image with each class so that I can display a list of classes and have a unique image for each.
I've tried searching SO and the internet for an answer, but can't find anything definite. Any help would be greatly appreciated.
Thanks,
Kyle
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建一个 ImageAttribute。
或者数据库 ID,只是识别图像的某种方式。
You could create an ImageAttribute.
Or database id, just some way to identify an image.
通过各种想法弄清楚如何做到这一点。
将图像标记为嵌入资源。
创建用于指定图像名称的属性。
读取图像名称属性后,使用以下命令在声明该类的程序集中找到图像资源:
Figured out how to do it using ideas here and there.
Mark the image as an EmbeddedResource.
Create an attribute for specifying the image name.
Once the image name attribute is read, use the following to locate the image resource inside the assembly where the class was declared: