zoukankan
html css js c++ java
补充一个技术文章吧,否则真的对不起博客园
/**/
///
<summary>
较安全的返回指定属性的值
</summary>
///
<remarks>
///
例如,如果你想获得Company的CompanyCode的DefaultCode属性,可以使用
///
<code>
///
object code = _company.SafeGetValue("CompanyCode.DefaultCode");
///
</code>
///
但注意:
///
传入的参数(属性名)不允许书写错误,在此方法中不对此进行检查;
///
</remarks>
public
object
SafeGetValue(
string
propertyName)
{
string
[] props
=
propertyName.Split(
'
.
'
);
string
propName;
PropertyInfo propInfo;
object
obj
=
this
;
Type objType;
for
(
int
i
=
0
; i
<
props.Length; i
++
)
{
objType
=
obj.GetType();
propName
=
props[i];
if
(propName.Trim().Length
==
0
)
throw
new
ArgumentException(
"
propertyName
"
);
try
{
propInfo
=
objType.GetProperty(propName);
if
(propInfo
==
null
)
throw
new
ArgumentException(
"
propertyName
"
);
obj
=
propInfo.GetValue(obj,
null
);
}
catch
(AmbiguousMatchException)
{
PropertyDescriptorCollection propDescs
=
TypeDescriptor.GetProperties(objType);
PropertyDescriptor propDesc
=
propDescs.Find(propName,
false
);
if
(propDesc
==
null
)
throw
new
ArgumentException(
"
propertyName
"
);
else
{
obj
=
propDesc.GetValue(obj);
}
}
if
(obj
==
null
)
return
null
;
}
return
obj;
}
查看全文
相关阅读:
使用接口测试活动的中奖概率(随机事件测试)
关于测试用例冗余的一些思考
正则表达式经典实例
自动化测试断言Assent的使用
equals与==区别
Git的使用以及GitHub
django的配置文件字符串是怎么导入的?
支付宝支付相关开发
Django的contenttypes
推荐课程及用户登录
原文地址:https://www.cnblogs.com/tansm/p/83582.html
最新文章
利用ansible批量部署zabbix-agent
centos7搭建ELK Cluster集群日志分析平台(四):Fliebeat-简单测试
centos7搭建ELK Cluster集群日志分析平台(三):Kibana
centos7搭建ELK Cluster集群日志分析平台(二):Logstash
centos7搭建ELK Cluster集群日志分析平台(一):Elasticsearch
转:异常处理之ThreadException、unhandledException及多线程异常处理
转:C#线程系列讲座(1) BeginInvoke和EndInvoke方法
转:C# 对委托的BeginInvoke,EndInvoke 及Control 的BeginInvoke,EndInvoke 的理解
转:C#判断ContextMenuStrip右键菜单的来源(从哪个控件弹出来的)
转:限制应用程序运行一次并激活已经运行的程序 .
热门文章
转:"为自动填充列调整大小期间不能执行此操作"解决办法 .
转:C# 使用资源文件 Resource.resx 的方法
实现Winform 跨线程安全访问UI控件
转:C# 小数位数保留的方法集锦
SQL 语法速记
jmeter定时器
NetBeans IDE驱动报错The path to the driver executable must be set by the web driver.chrome.driver.system property......
IDEA使用switch传入String编译不通过
Appium与Robotium区别
接口测试总结
Copyright © 2011-2022 走看看