zoukankan      html  css  js  c++  java
  • C# System.Reflection.Assembly动态加载资源文件

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

    核心代码:

     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;
                }
    

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

  • 相关阅读:
    Java 高级文件处理
    drf10
    drf9
    drf8
    drf7
    drf6
    drf5
    drf4
    drf3
    drf2
  • 原文地址:https://www.cnblogs.com/sunliyuan/p/11759007.html
Copyright © 2011-2022 走看看