c# 反射取其他项目的资源文件

反射获取其他项目里面的资源文件。

dll或exe里面

try
{
    System.Reflection.Assembly dll = System.Reflection.Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "Test.exe");
    ResourceManager resourceManager = new ResourceManager(dll.GetName().Name + ".Properties.Resources", dll);
    object obj = resourceManager.GetObject(picName.Replace('-', '_'));
    if (obj == null) return new Bitmap(22, 16);
    return ((System.Drawing.Bitmap)(obj));
}
catch
{
    throw new ArgumentException("获取图片失败!");
}

 

posted @ 2014-05-12 13:45  脸谱匠  阅读(743)  评论(0编辑  收藏  举报