[英]EmitMapper with object source type
I need to use emitmapper with diffirent types. 我需要对不同类型使用emitmapper。 For defoult it takes two generic types:
对于默认而言,它采用两种通用类型:
ObjectMapperManager.DefaultInstance.GetMapper<TSource, TEntity>().Map(source, result);
I need do something like this: 我需要做这样的事情:
class Result { public string Name { set; get;} public int Age {set; get;} }
...
Result result;
object someType = new SomeTypes { Name = "TestName", Age = 23 }
ObjectMapperManager.DefaultInstance.GetMapper<object, Result >().Map(source, result);
Console.WriteLine(result.Name);
AFAIK you can't do this with EmitMapper. 抱歉,您无法使用EmitMapper执行此操作。 You could with AutoMapper .
您可以使用AutoMapper 。 The feature is dynamic mapping:
该功能是动态映射:
object someType = new SomeTypes { Name = "TestName", Age = 23 }
var result = Mapper.DynamicMap<Result>(someType);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.