[英]C# AutoMapper Generic Mapping Class
我正在嘗試做通用映射器類
Mapper.Map<來源,目的地>(來源); 我收到錯誤
錯誤消息是(非靜態字段方法或屬性需要對象引用)
public class AutoMapperHelper<TSource, TDestination> where TDestination : class where TSource : class
{
public TDestination Map(TSource entity)
{
var source = new Source<TSource>()
{
Value = entity
};
var dest = Mapper.Map<Source<TSource>, Destination<TDestination>>(source);
return dest.Value;
}
}
public class Source<T>
{
public T Value { get; set; }
}
public class Destination<T>
{
public T Value { get; set; }
}
對於非靜態字段,該錯誤似乎為空引用。
試試下面
public class Source<T> where T:class
{
public T Value { get; set; }
}
public class Destination<T> where T:class
{
public T Value { get; set; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.