
正文
C#两个实体之间相同属性的映射
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
public static R Mapping<R, T>(T model)
{
R result = Activator.CreateInstance<R>();
foreach(PropertyInfo info in typeof(R).GetProperties())
{
PropertyInfo pro = typeof(T).GetProperty(info.Name);
if (pro != null)
info.SetValue(result, pro.GetValue(model));
}
return result;
}
R代表目标实体 T代表数据源实体






