首页 > Windows开发 > 详细

C# System.Reflection.Assembly动态加载资源文件

时间:2019-10-29 16:42:36      阅读:148      评论:0      收藏:0      [点我收藏+]

需求:需要做甘特图的显示,并且在甘特中加载图片。图片太多,写判断代码太多。用反射吧。

核心代码:

 try
            {
                if (stateColour < 0) return null;
                System.Reflection.Assembly dll = System.Reflection.Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "WeGanttGmTask.dll");
                string _stateName = GetEnumStrByNum(stateColour);
                _stateName = taskName + _stateName; //图片的名称
                ResourceManager resourceManager = new ResourceManager(dll.GetName().Name + ".Properties.Resources",dll );
                object obj = resourceManager.GetObject(_stateName);
                if (obj == null) return new Bitmap(22, 16);
                Image img = ((System.Drawing.Bitmap)(obj));
                return img;
            }
            catch(Exception e)
            {
                throw e;
            }

  以上的代码,就能获取到资源文件。

C# System.Reflection.Assembly动态加载资源文件

原文:https://www.cnblogs.com/sunliyuan/p/11759007.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!