打造一个商业软件,资源和本地化信息通常是作为一个独立的程序集实现的.
我的做法是参考WIN32的做法,把资源作为一个DLL实现.这样似乎性能上比resx要好.至少尺寸更小.
1.在vs2003新建一个DLL项目,把你的所有文件放进去,属性选择为嵌入的资源,这样就把2进制文件打包了.
2.对于字符串资源,首选建立一个类,然后把字符串作为公有静态STRING字段成员.这样就可以通过Type.GetField("FieldName").GetValue(null)来引用了,这样做最简单.
例子:
假设有这样个资源类
public class StringZH
{
public static string JpgName = "Jpg文件";
}
我们可以用以下方法得到JpgName的值:[注意,对于资源DLL,我们应该在运行时载入,而不是通过早期绑定[即引用]得到.]











上面主要是通过反射的方法得到,因为字符串作为公有静态STRING字段成员,我们就没有必要去实例化StringZH,这很好!如果你的资源类实现了某些实例方法,那你就必须实例化StringZH了.