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,改从资源文件中获取。
就这么简单。
查看全文
相关阅读:
加入mapstruct后出现 找不到符号 符号: 方法 setXX 的解决方法
解决docker容器日志导致主机磁盘空间满了的情况
prometheus安装(docker)
在Github或Gitee上用hexo搭建个人博客
解决github打不开
jenkins更新为国内源
让sentinel-dashboard的流控配置持久化到nacos
Yarn和Zookeeper的区别
flink安装启动(docker)
jQuery 事件源码定位
原文地址:https://www.cnblogs.com/tansm/p/266563.html
最新文章
关于WSL(Windows上的Linux子系统)的简单介绍及安装
10分钟开始.Net Core
Java并发基础(上)——Thread
关于mysql-connector-java(JDBC驱动)的一些坑
ASP.NET MVC——模型绑定
ASP.NET MVC——CodeFirst开发模式
ASP.NET MVC——Razor视图引擎
ASP.NET MVC——URL路由
小试ASP.NET MVC——一个邀请页面的实现
初识ASP.NET MVC
热门文章
IDEA激活(2018.2.5)
mysql工具类日志(binlog、slowlog、errorlog)
mysql使用1(用户+权限)
安装mysql二进制版
删除centos7默认openjdk并安装jdk1.8并编写测试代码
HashMap和布隆过滤器命中性能测试
HttpUrlConnection工具类
自定义ThreadLocal和事务(基于自定义AOP)
自定义Aspect风格的AOP框架
JDK动态代理和CGLIB动态代理编码
Copyright © 2011-2022 走看看