[EntLib]关于SR.Strings的使用办法[加了下载地址]

简介:
编写者:郑昀@UltraPower
安装String Resource Generator 1[1].2.5,运行SRGenerator.msi。
然后给自己的工程中添加SR.strings文件,通过VS.NET在现有的.RESXSR.strings文件设置Custom tool属性为:StringResourceToolSRCodeGen。然后就自动生成了SR.cs和SR.resx.
 
使用呢,比如:
我们在SR.strings文件中定义了一行:
ItemNotFoundMessage(key) =  Item not found in cache\r\n\tKey: {0}
那么我们在应用程序中就可以这样:
this.ResultsTextBox.Text += SR.ItemNotFoundMessage(selectItemForm.ItemKey) + "\r\n";
 
其实,这个SR.ItemNotFoundMessage的定义在自动生成的SR.CS文件中:
  public static string ItemNotFoundMessage (string key)
  {
   return Keys.GetString( Keys.ItemNotFoundMessage, key );
  }
 
这种传入方式很利于我们统一应用中的错误描述的生成方式。比如我们可以定义错误描述在SR.strings文件中:
LBS_Request_CannotConnectServer = 无法连接到远端LBS网关服务器:{0}
那么在实际调用时就可以这么:
catch(WebException ex)
{...
    sb.Append(SR.LBS_Request_CannotConnectServer(_Url) );
...
}
 
 
其他的SR.Strings定义方式还有:

Name

Value

Comments

Member on SR class

NotAuthorized

You are not authorized, go away

 

String NotAuthorized { get; }

ArgumentInvalid

Argument {0} is not valid

argumentName

String ArgumentInvalid(object argumentName);

ConnectionBad

Connection server: {0}, database {1} invalid

server,db

String ConnectionBad(object server, object db);

OtherStuff

This {0}, is undefined: {1}

 

String OtherStuff(object arg1, object arg2);


目录
相关文章
|
5月前
|
测试技术
【LaTex】10 从md文件导入\导出word (因为:Typora-版本过高不能转换word 报错:Unknown option --atx-headers. )
【LaTex】10 从md文件导入\导出word (因为:Typora-版本过高不能转换word 报错:Unknown option --atx-headers. )
156 7
|
5月前
|
前端开发 Linux Docker
【源码共读】跨平台打开 URL、文件、可执行文件 open
【源码共读】跨平台打开 URL、文件、可执行文件 open
78 1
|
Oracle Java 关系型数据库
华为云aarch64架构下载jdk;Linux上jdk无法执行二进制文件及​gzip: stdin: invalid compressed data–format violated​报错
华为云aarch64架构下载jdk;Linux上jdk无法执行二进制文件及​gzip: stdin: invalid compressed data–format violated​报错
550 0
|
芯片 内存技术
MDK 下载程序出现no target connected 导致下载失败
MDK 下载程序出现no target connected 导致下载失败
534 0
MDK 下载程序出现no target connected 导致下载失败
关于 海思平台sample的demo中添加ffmpeg静态库(.a)报错误undefined reference toavpriv_pix_fmt_hps_avi等错误 的解决方法
关于 海思平台sample的demo中添加ffmpeg静态库(.a)报错误undefined reference toavpriv_pix_fmt_hps_avi等错误 的解决方法
关于 海思平台sample的demo中添加ffmpeg静态库(.a)报错误undefined reference toavpriv_pix_fmt_hps_avi等错误 的解决方法
关于 国产麒麟系统编译Qt项目是报错:error: cannot find -lGL 的解决方法
关于 国产麒麟系统编译Qt项目是报错:error: cannot find -lGL 的解决方法
关于 国产麒麟系统编译Qt项目是报错:error: cannot find -lGL 的解决方法
使用WebStorm 报错解决方法!!Unable to save settings: Failed to save settings (内含注册码破解码)
使用WebStorm 报错解决方法!!Unable to save settings: Failed to save settings (内含注册码破解码)
584 0
使用WebStorm 报错解决方法!!Unable to save settings: Failed to save settings (内含注册码破解码)
|
前端开发
前端 ✘ http://eslint.org/docs/rules/quotes Strings must use singlequote 报错解决方法
前端 ✘ http://eslint.org/docs/rules/quotes Strings must use singlequote 报错解决方法
308 0
openpyxl库由于不支持数据验证扩展导致的读取excel报“Data Validation extension is not supported and will be removed“错解决方法
openpyxl库由于不支持数据验证扩展导致的读取excel报“Data Validation extension is not supported and will be removed“错解决方法
2287 0
openpyxl库由于不支持数据验证扩展导致的读取excel报“Data Validation extension is not supported and will be removed“错解决方法
|
数据可视化 Python
【pypi开源项目文档】终极秘诀应对rst解析错误:The description failed to render in the default format of reStructuredText
前面雷学委给大家缕一缕了如何开发一个python库并导入运行, 基本完成了一个初步的库,还支持了命令行工具的发布。
468 0
【pypi开源项目文档】终极秘诀应对rst解析错误:The description failed to render in the default format of reStructuredText