ResourceManager使用
来源:互联网 发布:linux 中搭建php环境 编辑:程序博客网 时间:2024/05/22 03:15
可以使用 ResourceManager 类在运行时检索“嵌入的资源”(即已经编译到应用程序或类库中的资源
ResourceManager 类的每个实例都与一个程序集关联并且管理对嵌入到该程序集中的资源的检索。
检索资源
- 创建一个程序集引用,引用包含要访问的资源的程序集。如果尚未加载包含资源的程序集,则必须在此时加载它。
- 创建 ResourceManager 类的实例以检索资源。
- 指定嵌入文件的基名称并提供对包含资源的程序集的引用。
注意 嵌入的资源文件的基名称是嵌入了资源文件的命名空间的名称加上不带任何扩展名的文件名。例如,myApplication 命名空间中名为 Resource1.resX 的文件的基名称是 myApplication.Resource1。
- 调用 ResourceManager.GetString 方法或 ResourceManager.GetObject 方法以检索资源。
- 若要检索“字符串”资源,请调用 GetString 方法。
- 若要检索其他类型的资源,请调用 GetObject 方法。通过 GetObject 方法检索到的资源必须显式转换成对应的类型。
demo1:
// Gets a reference to the same assembly that
// contains the type that is creating the ResourceManager.
System.Reflection.Assembly myAssembly;
MyAssembly = this.GetType().Assembly;
// Gets a reference to a different assembly.
System.Reflection.Assembly myOtherAssembly;
myOtherAssembly = System.Reflection.Assembly.Load("ResourceAssembly");
// Creates the ResourceManager.
System.Resources.ResourceManager myManager = new
System.Resources.ResourceManager("ResourceNamespace.myResources",
myAssembly);
// Retrieves String and Image resources.
System.String myString;
System.Drawing.Image myImage;
myString = myManager.GetString("StringResource");
myImage = (System.Drawing.Image)myManager.GetObject("ImageResource");
demo2:
using System;
using System.Resources;
using System.Threading;
using System.Reflection;
using System.Globalization;
class ResourcesExample
{
public static void Main()
{
// Create a resource manager to retrieve resources.
ResourceManager rm = new ResourceManager("resourceManager.Application",
Assembly.GetExecutingAssembly());
// Get the culture of the currently executing thread.
// The value of ci will determine the culture of
// the resources that the resource manager retrieves.
CultureInfo ci = Thread.CurrentThread.CurrentCulture;
// Retrieve the value of the string resource named
// "welcome", localized for the culture specified by ci.
String str = rm.GetString("welcome", System.Globalization.CultureInfo.CurrentCulture);
Console.WriteLine(str);
}
}
资源文件必须写成,程序集名字.资源文件名不包括扩展名
转载:http://blog.csdn.net/RainyLin/article/details/2108683
- ResourceManager使用
- ResourceManager使用
- ResourceManager
- ResourceManager
- 使用 ResourceManager 类检索资源(来自MSDN)
- 资源管理ResourceManager
- TinyRenderEngine------ResourceManager
- ResourceManager HA
- ResourceManager HA
- Resourcemanager HA
- ResourceManager GC
- yarn ResourceManager
- 如何使用ResourceManger,及使用ResourceManager过程中出错的找不到资源的错误
- 如何使用ResourceManger,及使用ResourceManager过程中出错的找不到资源的错误
- 一个使用模板,并具有模板和派生双重灵活性的ResourceManager
- ResourceManager的名字问题
- ActionScript 绑定 resourceManager
- YARN ResourceManager failover机制
- javascript 学习笔记(四)
- java将去除多余只留一个空格
- ORACLE下删除当前用户下所有对象 等等
- MFC 读写配置文件
- [内核文档]RCU相关概念
- ResourceManager使用
- TCP三次握手连接及seq和ack号的正确理解
- CD光盘版本对音质的影响
- linuxshell 读书笔记六 (unix shell 第三版)
- 在matlab中加入文件夹搜索路径和去除文件夹搜索路径
- 工作中碰到的memory footprint很高的问题
- 苹果反间谍趣闻:曾把产品放在番茄箱子里运输
- Activity的taskAffinity属性
- 整型和字符串相互转化