namespace CloudGaming.Core.Mappers;
///
/// 对象映射类
///
public static class ObjectMapper
{
///
/// copy object
///
/// 旧对象类型
/// 新复制对象类型
///
///
public static TNew? MapTo(this TOld source)
{
if (source == null) return default;
var config = new MapperConfiguration(cfg => cfg.CreateMap());
var mapper = config.CreateMapper();
return mapper.Map(source);
}
///
/// copy object
///
///
///
///
///
///
public static TNew? MapTo(this TOld source, TNew @new)
{
if (source == null) return default;
var config = new MapperConfiguration(cfg => cfg.CreateMap());
var mapper = config.CreateMapper();
return mapper.Map(source, @new);
}
///
/// copy list
///
/// 旧对象类型
/// 新复制对象类型
///
///
public static List? MapToList(this IEnumerable source)
{
if (source == null) return default;
var config = new MapperConfiguration(cfg => cfg.CreateMap());
var mapper = config.CreateMapper();
return mapper.Map>(source);
}
}