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,改从资源文件中获取。
就这么简单。
查看全文
相关阅读:
perl 分析binlog
perl 替换
perl s s* s+
17.3.2 Using Replication with Different Master and Slave Storage Engines
17.3.1.1 Backing Up a Slave Using mysqldump
MySQL时间戳和日期相互转化
MySQL中ROUND和TRUNCATE的区别
17.3 Replication Solutions
17.2.2.2 Slave Status Logs
relay-log命名规则
原文地址:https://www.cnblogs.com/tansm/p/266563.html
最新文章
8.2.1.5 Engine Condition Pushdown Optimization
8.2.1.4 Index Merge Optimization 索引合并优化
8.2.1.3 Range Optimization 范围优化
CAS实现单点登录(SSO)经典完整教程
8.2.1.2 How MySQL Optimizes WHERE Clauses 如何优化mySQL WHERE子句:
8.2.1.1 Speed of SELECT Statements 加速SELECT 语句:
Could not resolve placeholder 'jdbc.username' in string value "${jdbc.username}"
错误代码: 1048 Column 'typeId' cannot be null
错误代码: 1100 Table 't_depart_info' was not locked with LOCK TABLES
8.1 Optimization Overview 优化概述
热门文章
Myeclipse中java项目转成Web项目
Chapter 8 Optimization 调优
错误代码: 1366 Incorrect integer value: 'zhangsan' for column 'depart_teacher' at row 1
MySQL中的DATE_ADD应用场景
HTML5中的save()和restore()方法的用法
TypeError: canvas is null
Submitted credentials for token did not match the expected credentials.
17.3.4 Replicating Different Databases to Different Slaves 复制不同的数据库到不同的Slaves
17.3.3 Using Replication for Scale-Out 使用复制扩展
发邮件
Copyright © 2011-2022 走看看