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,改从资源文件中获取。
就这么简单。
查看全文
相关阅读:
Magento:Paypal付款不成功返回后不要清空购物车产品的解决方案
magento设置订单状态
linux下查看所有用户以及用户组
网站无法访问的原因
magento 多域名多店铺
linode空间lamp环境的搭建
hp p410固件更新
tracert
镜像架设
nohup
原文地址:https://www.cnblogs.com/tansm/p/266563.html
最新文章
Python 上下文管理器:控制输出的结果能同时保存到文件中
win10 取消输入法的快捷键 Ctrl+space
Ubuntu上多台服务器相互挂载文件夹
几种异常点检测算法
biLSTM 函数调用 与模型参照 (Tensorflow)
c学习笔记
两个秘诀和四句话
一个男人所关心的东西决定了他的层次
magento性能优化
Magento Soap Api接口出错无法使用
热门文章
Magento后台表单字段添加备注
Magento后台Grid删除Add New按钮
怎么书写高质量jQuery代码
XML HttpRequest
jquery学习笔记
Gmail邮箱添加域名解析
JavaScript 开发的45个经典技巧
[转载]Magento 店铺多语言设置
magento产品成功添加到购物车后跳转到不同页面 添加 add to cart 按钮
magento添加多个产品到购物车(Add multiple products to cart )
Copyright © 2011-2022 走看看