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,改从资源文件中获取。
就这么简单。
查看全文
相关阅读:
unity3d热更新插件uLua学习整理
结合axios对项目中的api请求进行封装
移动端适配剖析
vscode如何调试node项目(给node项目打断点)
mac上使用cnpm搭建npm私有仓库,并上传/下载私有npm包
前端常见的兼容性问题--web端和移动端
react树形选择组(支持:单选,多选,全选)
MongoDB 与 Mysql 的对比
使用div 的 contenteditable属性,实现输入编辑,输入 "#" 出现下拉选择
前端单元测试,以及给现有的vue项目添加jest + Vue Test Utils的配置
原文地址:https://www.cnblogs.com/tansm/p/266563.html
最新文章
ubuntu 中 ThinkPHP 上传文件无法得到文件名
Ubuntu Git安装
Ubuntu_16.04 配置 Apache Rwrite URL 重写
redis主从中断异常处理
MySQL 5.7使用xtabackup报错解决
Redis集群迁移
Redis集群迁移
探究MySQL MGR的读写分离
redis集群热扩展(基于4.0.9)
sqlserver的资源调控器
热门文章
一些简单的SQL Server服务器监控
alwayson监控
从MySQL向Greenplum集群中导入数据
测试网络获取以太币
高深的密码学+复杂的区块链,其实也可以通俗易懂
加密货币的本质
比特币入门
区块链入门教程
shader 编程入门(一)
Unity中使用ulua的个人经验总结
Copyright © 2011-2022 走看看