简体   繁体   English

具有对象源类型的EmitMapper

[英]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.

相关问题 EmitMapper-从抽象模型对象到抽象DTO的通用映射 - EmitMapper - Generic mapping from abstract model object to abstract DTO 使用SqlQuery时,“source不是IEnumerable &lt;&gt;”错误(Type,string,object [])。AsQueryable() - “source is not IEnumerable<>” error when using SqlQuery(Type,string,object[]).AsQueryable() 反序列化类型为&lt;&gt;的对象时发生错误输入源的格式不正确 - There was an error deserializing the object of type <> The input source is not correctly formatted 无法找到源类型“对象”的查询模式的实现。 找不到“选择” - Could not find an implementation of the query pattern for source type 'object'. 'Select' not found 当源中的所有内容都是数组但目标对象类型不是时,反序列化 Json 文档 - Deserialize Json document when everything in source is an array, but target object type is not 自动映射器:将类型X的属性从源对象映射到目标对象,并将等值属性映射为类型X - Automapper: Map property of type X from source object to destination object with equivlanet properties to type X EmitMapper 的列表映射问题与 Collections - EmitMapper's List Mapping Issue with Collections 获取源成员类型 - Getting the source member type 无法从源类型转换为目标类型(JNIEnv.GetArray <Java.Lang.Object> (pudis.Handle);) - Cannot cast from source type to destination type (JNIEnv.GetArray<Java.Lang.Object>(pudis.Handle);) XAML编辑器为SharedResourceDictionary.Source抱怨“对象与目标类型不匹配” - XAML editor complains “Object does not match target type” for SharedResourceDictionary.Source
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM