zoukankan
html css js c++ java
让你的控件属性注释支持多语言
我们知道在开发控件时,可以为某个属性添加
DescriptionAttribute
标记,就可以在属性栏中显示他的注释,像下面这样:
private
int
_qua;
[Description(
"
此订单明细的数量
"
)]
public
int
Qua
{
get
{
return
_qua; }
set
{ _qua
=
value; }
}
但你会发现,注释的字符串是中文文本写死的,如果我希望控件在英文的环境下显示英文的注释应该怎么办呢?.NET Framework就可以显示不同语言的注释,他是怎么解决的呢?
反编译.NET Framework,我们发现他的注释并没有
DescriptionAttribute,而是使用了S
RDescriptionAttribute
,例如:
[SRDescription(
"
ControlBottomDescr
"
)]
public
int
Bottom
{
get
{
return
(
this
.y
+
this
.height);
}
}
在注释中,.NET Framework没有的确没有直接写英文注释,而是写了一个资源关键字,再查看
SRDescriptionAttribute
的实现。
[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,改从资源文件中获取。
就这么简单。
查看全文
相关阅读:
对焦过程中消除摩尔纹
Python3.x:Linux下安装python3.6
Python3.x:Linux下退出python命令行
Python3.x:ConfigParser模块的使用
Python3.x:SQLAlchemy操作数据库
Python3.x:遍历select下拉框获取value值
Python3.x:Selenium中的webdriver进行页面元素定位
Python3.x:selenium获取iframe内嵌页面的源码
Python3.x:Selenium+PhantomJS爬取带Ajax、Js的网页
Python3.x:将数据下载到xls时候用xml格式保存一份读取内容
原文地址:https://www.cnblogs.com/tansm/p/266563.html
最新文章
RabbitMQ原理
Ehcache(08)——可阻塞的Cache——BlockingCache
Ehcache(07)——Ehcache对并发的支持
Ehcache(06)——监听器
Ehcache(05)——缓存的查询
Ehcache(04)——设置缓存的大小
Ehcache(03)——Ehcache中储存缓存的方式
Ehcache(02)——ehcache.xml简介
Ehcache(01)——简介、基本操作
java加密解密研究6、MD算法家族
热门文章
mysql变量使用总结(转)
努比亚Z18mini多点对焦
各类相机中的对焦技术汇总【乱】
忽闻岸上踏歌声
春溪尚梦浅
多点自动对焦技术汇总记录【乱】
被动对焦中的相位对焦与反差对焦
相机的对焦与合焦
典型无参考图像清晰度评价(可用作对焦评价函数)
FIR滤波器与IIR滤波器
Copyright © 2011-2022 走看看