zoukankan      html  css  js  c++  java
  • C#资源文件与与资源名称字符串之间的互相转化

    1.使用ResourceManager

    string st = Properties.Resources.ResourceManager.GetString(tableName);
    value = Properties.Resources.ResourceManager.GetObject(fileName, Properties.Resources.Culture)

    public static Bitmap GetImageByName(string imageName)
    {
    System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
    string resourceName = asm.GetName().Name + ".Properties.Resources";
    var rm = new System.Resources.ResourceManager(resourceName, asm);
    return (Bitmap)rm.GetObject(imageName);

    }

    2. 使用反射

    var type = typeof(Properties.Resources);
    var property = type.GetProperty(fileName, BindingFlags.Static| BindingFlags.NonPublic|BindingFlags.Public);
    var value = property.GetValue(null, null);

  • 相关阅读:
    16款值得一用的iPhone线框图模板 (PSD & Sketch)
    设计神器
    {CF812}
    hiho1080(多标记线段树)
    {容斥原理}
    {dp入门}
    {AC自动机}
    CF807
    Trie树
    杂记
  • 原文地址:https://www.cnblogs.com/zcm123/p/4453499.html
Copyright © 2011-2022 走看看