有时我们知道一个资源的名称和程序集,需要读出该资源文件,用以下方法可以智能的读出,而不需要知道资源根名称.

 

public static object GetResources(System.Reflection.Assembly assembly, string AResName) {
foreach (string s in assembly.GetManifestResourceNames())
{
if (!s.EndsWith("resources")) continue;
System.Resources.ResourceManager resMan = new System.Resources.ResourceManager(s.Substring(0, s.Length - ".Resources".Length), assembly);
object obj = resMan.GetObject(AResName);
if (obj != null) return obj;
}
return null;
}

 

此方法未优化,如果有大量的资源需要加载,有优化的余地.

相关文章:

  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2021-12-12
  • 2022-02-04
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-03-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2021-09-10
相关资源
相似解决方案