//解决问题,两个类字段相同,但是类名不一样,如何进行赋值,通过反射进行逐一字段读取然后赋值
var DuanXinType = new DuanXin();
DuanXinType.RECEIVE_LOGIN_NAME = "cwh";
DuanXinType.RECEIVE_Number = "13800138000";
var typeduanxin = typeof(DuanXin);
var PropertyInfoDuanxin = typeduanxin.GetProperties();
WeChat pWeChat = new WeChat();
var typeWeChat = typeof(WeChat);
var PropertyInfosWeChat = typeWeChat.GetProperties();
foreach (var itemduanxin in PropertyInfoDuanxin)
{
var objDuanXinType = itemduanxin.GetValue(DuanXinType);
foreach (var itemWeChat in PropertyInfosWeChat)
{
if (itemduanxin.Name == itemWeChat.Name)
{
itemWeChat.SetValue(pWeChat, objDuanXinType, null);
}
}
}
c# 类名不同,字段相同,如何快速给类赋值
最新推荐文章于 2024-02-20 15:17:56 发布