runxinzhi.com
首页
百度搜索
让你的控件属性注释支持多语言
我们知道在开发控件时,可以为某个属性添加
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,改从资源文件中获取。
就这么简单。
相关阅读:
管理员必备的Linux系统监控工具
kafka入门:简介、使用场景、设计原理、主要配置及集群搭建(转)
RedHat linux配置yum本地资源
RedHat Linux RHEL6配置本地YUM源
c语言中的fgets函数
sprintf()函数的用法
spring boot整合JWT例子
spring boot 自定义过滤器链
(转)ArrayList和LinkedList的几种循环遍历方式及性能对比分析
(转)Springboot 中filter 注入对象
原文地址:https://www.cnblogs.com/tansm/p/266563.html
最新文章
PowerDesigner中Table视图怎样同时显示Code和Name
MVC中视图View向控制器传值的方法
MVC控制器向View视图传值的三种方法
vs2012 编译运行报 项目程序包Dsp.Bds.dll还原失败,找不到版本xxxxxx的程序包问题的解决方法
JqGrid获得所有选中行数据ID数组,获取所有行的ID数组
在选中行的时候不选中复选框
MVC日期和其它字符串格式化
MSSQL语句批量替换表中某列字段内容的某个字符
【转】SQL2008的sa账户被禁用,其他账户无法连接的解决方法
直接使用提交过来的类来更新字段EntityState.Modified并过滤null值的方法
热门文章
EF5.0增删改查的写法及执行Sql的方法
在JS中设置Select和radio选中
C#怎样去掉对于用Splict分隔的数组中的空值?
Linux命令lsb_release:查看当前系统的发行版信息
va_list深究
Kafka入门经典教程
C语言之strrchr函数
centos yum 安装
深入浅出JMS(一)--JMS基本概念
PPTP(Point to Point Tunneling Protocol),即点对点隧道协议。
Copyright © 2020-2023
润新知