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,改从资源文件中获取。
就这么简单。
查看全文
相关阅读:
mysql获取插入时自增ID值的方法
percona-toolkit介绍及安装
mysql如何修改所有的definer
Mysql数据库安全管理配置
mysql update时报错You are using safe update mode
mysql修改definer方法
mysqldump: Couldn't execute 'show table status '解决方法
Linux下修改PATH路径
mysql 查看当前登陆用户匹配原则及权限user()与current_user()
ASP.NET MVC post请求接收参数的三种方式
原文地址:https://www.cnblogs.com/tansm/p/266563.html
最新文章
JavaWeb学习笔记——Tomcat配置
Android之帮助文档
Android学习笔记——xml
Android学习笔记——SQLite
Android学习笔记——menu
Android学习笔记——LinearLayout
Android学习笔记——MixLayout
Android学习笔记——TableLayout
Android学习笔记——ListView
Android学习笔记——ProgressBarHandler
热门文章
java.lang.String 的 + 号操作到底做了什么?
一份详尽的 Java 问题排查工具清单,值得收藏!
这 17 个 JVM 参数,高级 Java 必须掌握!
一个很艰难的 Java 核心面试问题!
ArrayList 为啥要实现 RandomAccess 接口?
Spring Boot 如何做参数校验?
教你在 IntelliJ IDEA 中使用 VIM!
CPU飙高,频繁GC,怎么排查?
Java开发必知道的国外10大网站
Mysql中的各种timeout
Copyright © 2011-2022 走看看