我的WEB编程世界
路是靠脚走出来的,能力是靠手和大脑练出来的。
登录
注册
全站
当前博客
空间
博客
好友
相册
留言
遍历类的属性,并给类的属性赋值|取值
收藏
遍历类的属性,并给类的属性赋值|取值
平时自己写的,收藏一下。
public
sealed
class
Common
...
{
public
static
void
Charge
<
oT, nT
>
(oT oldClass, nT newClass)
...
{
Type tOld
=
oldClass.GetType();
Type tNew
=
newClass.GetType();
foreach
(PropertyInfo piOld
in
tOld.GetProperties())
...
{
foreach
(PropertyInfo piNew
in
tNew.GetProperties())
...
{
if
(piOld.Name.Equals(piNew.Name))
...
{
piOld.SetValue(oldClass, piNew.GetValue(newClass,
null
),
null
);
break
;
}
}
}
}
public
static
void
Charges
<
oT, nT
>
(
ref
List
<
oT
>
oldClasses, nT[] newClass)
where
oT :
new
()
...
{
for
(
int
i
=
0
; i
<
newClass.Length; i
++
)
...
{
oT ot
=
new
oT();
Charge
<
oT, nT
>
(ot, newClass[i]);
oldClasses.Add(ot);
}
}
}
发表于 @
2008年04月10日 14:42:00
|
评论(
loading...
)
新一篇: 程序内部通过Code调用URL文件。
|
旧一篇: 使用调度程序构建反应速度更快的应用程序(续..)
用户操作
[即时聊天]
[发私信]
[加为好友]
不然
订阅我的博客
不然的公告
尼斯湖怪:深水传说
文章分类
收藏
存档
2008年05月(1)
2008年04月(1)
2008年01月(3)
2007年12月(1)
2007年08月(1)
2007年06月(2)
2007年05月(5)
2007年04月(10)
2007年03月(8)
软件项目交易