获取程序资源 Resources

 获取程序资源 Pagebase.cs 中。获取数据:Resources["ADDNEW_SUCCESS"]
/// <summary>
/// 获取程序资源
/// </summary>
protected static ResourcesCollection Resources = new ResourcesCollection( Assembly.GetExecutingAssembly(),"Info");

获取程序资源对应的资源文件:Resources/Info.resx

using System;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
namespace ZF_ERP.Common
{
 /// <summary>
 ///日期:-12-19 签名:lj
 ///获取程序资源对应的资源文件:Resources/Info.resx
 /// </summary>
 public class ResourcesCollection
 {
  private ResourceManager m_resourceManager;

  /// <summary>
  /// 获取程序资源
  /// </summary>
  /// <param name="assembly">当前运行的程序集</param>
  /// <param name="assemblyType">获取的资源类型。SqlCmd:SQL语句;Info:提示信息</param>
  public ResourcesCollection( Assembly assembly,string assemblyType)
  {
   string assemblyName="";
   switch (assemblyType.ToUpper())
   {
     //m_resourceManager = new ResourceManager( assembly.GetName().Name, assembly );
    case "SQLCMD":
     assemblyName=assembly.GetName().Name+".Resources.SqlCmd";
     break;
    case "INFO":
     assemblyName=assembly.GetName().Name+".Resources.Info";
     break; 
   }
   m_resourceManager = new ResourceManager(assemblyName, assembly );   
  }


  /// <summary>
  /// Default property for accessing resources
  /// <param name="index">
  /// Index for the desired resource</param>
  /// <returns>
  /// Resource string value</returns>
  ///</summary>

  public string this[ Enum index ]
  {
   get
   {
    return m_resourceManager.GetString( index.GetType().Name + "." + Enum.Format( index.GetType(), index, "G" ) );
   }
  }


  /// <summary>
  /// Default property for accessing resources
  /// <param name="name">
  /// Name of the desired resource</param>
  /// <returns>
  /// Resource string value</returns>
  /// </summary>

  public string this[ string name ]
  {
   get
   {
    return m_resourceManager.GetString( name );
   }
  }
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值