让你的控件属性注释支持多语言
2005-11-01 18:46
288 查看
我们知道在开发控件时,可以为某个属性添加DescriptionAttribute标记,就可以在属性栏中显示他的注释,像下面这样:
private int _qua;
[Description("此订单明细的数量")]
但你会发现,注释的字符串是中文文本写死的,如果我希望控件在英文的环境下显示英文的注释应该怎么办呢?.NET Framework就可以显示不同语言的注释,他是怎么解决的呢?
反编译.NET Framework,我们发现他的注释并没有DescriptionAttribute,而是使用了SRDescriptionAttribute ,例如:
[SRDescription("ControlBottomDescr")]
[AttributeUsage(AttributeTargets.All)]
internal sealed class SRDescriptionAttribute : DescriptionAttribute {
private bool replaced;
public SRDescriptionAttribute(string description)
: base(description) {
}
public override string Description {
get {
if (!this.replaced) {
this.replaced = true;
base.DescriptionValue = SR.GetString(base.Description);
}
return base.Description;
}
}
}
太简单,太巧妙了,他重载了Description的Get,改从资源文件中获取。
就这么简单。
private int _qua;
[Description("此订单明细的数量")]
但你会发现,注释的字符串是中文文本写死的,如果我希望控件在英文的环境下显示英文的注释应该怎么办呢?.NET Framework就可以显示不同语言的注释,他是怎么解决的呢?
反编译.NET Framework,我们发现他的注释并没有DescriptionAttribute,而是使用了SRDescriptionAttribute ,例如:
[SRDescription("ControlBottomDescr")]
[AttributeUsage(AttributeTargets.All)]
internal sealed class SRDescriptionAttribute : DescriptionAttribute {
private bool replaced;
public SRDescriptionAttribute(string description)
: base(description) {
}
public override string Description {
get {
if (!this.replaced) {
this.replaced = true;
base.DescriptionValue = SR.GetString(base.Description);
}
return base.Description;
}
}
}
太简单,太巧妙了,他重载了Description的Get,改从资源文件中获取。
就这么简单。
相关文章推荐
- 让你的控件属性注释支持多语言
- 让你的控件属性注释支持多语言
- 让Silverlight AutoCompleteBox控件支持多属性筛选
- iOS系统控件,支持多语言
- uustepcount 好用的代码行数统计工具,支持js等语言,去除注释和空格
- .Net 用户控件中复杂属性的设计时支持
- [集成IronPython] 使CLR对象对动态语言更友好(一)—— 支持运行时添加删除属性
- 发布首款支持Shift/Ctrl多选的国产日历控件,界面仿Twitter风格,支持中文日期类型,支持SImpleDateFormat格式,支持change等自定义事件,全中文注释和API,欢迎支持
- 富文本(TYAttributedLabel 简单,强大的属性文本控件(无需了解CoreText),支持图文混排显示,支持添加链接,image和UIView控件,支持自定义排版显示)
- [20081226更新(加了日文版本支持)]一个JavaScript WEB日历控件,支持IE6,FireFox,可支持不同语言版本,目前支持中文简繁,英,日语
- 如何使blend显示控件及属性的注释
- 服务端控件 对象不支持此属性或方法
- ASP.NET控件开发之属性设计时支持
- uploadify 控件的按钮不支持多国语言,这里介绍如何修改后使其支持多国语言。
- 用户控件中复杂属性的设计时支持
- C++ builder 遍历所有组件的 caption 属性,轻松实现界面多语言支持
- 备忘录:asp.net 用户控件 多语言支持 多工程 i18n
- office2007:您正试图运行的函数包含有宏或需要宏语言支持的内容。而在安装此软件时,您(或您的管理员)选择了不安装宏或控件的支持功能
- ie6 未结束注释,对象不支持此属性或方法等错误原因
- 一个JavaScript WEB日历控件,支持IE6,FireFox,可支持不同语言版本,目前支持中英文。