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;
}
查看全文
相关阅读:
硬币游戏 Project Euler 232
屏幕空间的近似全局光照明(Approximative Global Illumination in Screen Space)
四维之美
vertex texture fetching in HLSL, and heightfield normal calculation
一个VS小插件(跳出括号)
我的算法书籍收藏
Algorithms.算法概论.习题答案
UML用例图教程详解
大连理工大学软件学院博客地址
快递查询API,我推荐“爱快递”
原文地址:https://www.cnblogs.com/tansm/p/83582.html
最新文章
给博客增加RSS订阅到Google、鲜果、抓虾、QQ邮箱功能
如何:使用 LINQ to SharePoint 进行查询
在 SharePoint 2010 中访问数据
SPMetal语法用法
了解 PerformancePoint 仪表板设计器
BAE中实现WordPress固定链接及伪静态
WordPress删除数据中标题重复文章的方法
Wordpress调用文章第一张图片
BAE空间 Wpconfig配置
为Infopath2010重复表添加自动递增的行号
热门文章
用软件量度评估软件重构
离线应用的一种设计方案
基于petri网分析并发控制
比较几种编程语言
树形结构的节点搜索优化
利用ruby演示程序执行
MVC模式的两种实例
Screen Space Directional Occlusion
杂题几道
完全平方数的判定及整数平方根的快速求解
Copyright © 2011-2022 走看看