当前位置: 首页 > news >正文

网站主机一般选哪种的考百度指数 某个关键词在某个行业网站上的

网站主机一般选哪种的,考百度指数 某个关键词在某个行业网站上的,中国建行官方网站,网站打不开 域名做解析AutoMapper的匹配 1#xff0c;智能匹配 AutoMapper能够自动识别和匹配大部分对象属性: 如果源类和目标类的属性名称相同#xff0c;直接匹配#xff0c;不区分大小写目标类型的CustomerName可以匹配源类型的Customer.Name目标类型的Total可以匹配源类型的GetTotal()方法…AutoMapper的匹配      1智能匹配      AutoMapper能够自动识别和匹配大部分对象属性:     如果源类和目标类的属性名称相同直接匹配不区分大小写 目标类型的CustomerName可以匹配源类型的Customer.Name 目标类型的Total可以匹配源类型的GetTotal()方法    2自定义匹配     Mapper.CreateMapCalendarEvent, CalendarEventForm()                                                    //属性匹配匹配源类中WorkEvent.Date到EventDate     .ForMember(dest dest.EventDate, opt opt.MapFrom(src src.WorkEvent.Date))     .ForMember(dest dest.SomeValue, opt opt.Ignore())                                                 //忽略目标类中的属性     .ForMember(dest dest.TotalAmount, opt opt.MapFrom(src src.TotalAmount ?? 0))  //复杂的匹配     .ForMember(dest dest.OrderDate, opt opt.UserValueDateTime(DateTime.Now));      //固定值匹配 直接匹配 源类的属性名称和目标类的属性名称相同不区分大小写直接匹配Mapper.CreateMapsource,dest();无需做其他处理此处不再细述 Flattening  将一个复杂的对象模型拉伸为或者扁平化为一个简单的对象模型如下面这个复杂的对象模型 public class Order{private readonly IListOrderLineItem _orderLineItems new ListOrderLineItem();public Customer Customer { get; set; }public OrderLineItem[] GetOrderLineItems(){return _orderLineItems.ToArray();}public void AddOrderLineItem(Product product, int quantity){_orderLineItems.Add(new OrderLineItem(product, quantity));}public decimal GetTotal(){return _orderLineItems.Sum(li li.GetTotal());}}public class Product{public decimal Price { get; set; }public string Name { get; set; }}public class OrderLineItem{public OrderLineItem(Product product, int quantity){Product product;Quantity quantity;}public Product Product { get; private set; }public int Quantity { get; private set; }public decimal GetTotal(){return Quantity * Product.Price;}}public class Customer{public string Name { get; set; }} 我们要把这一复杂的对象简化为OrderDTO只包含某一场景所需要的数据 public class OrderDto{public string CustomerName { get; set; }public decimal Total { get; set; }} 运用AutoMapper转换 public void Example(){// Complex modelvar customer new Customer{Name George Costanza};var order new Order{Customer customer};var bosco new Product{Name Bosco,Price 4.99m};order.AddOrderLineItem(bosco, 15);// Configure AutoMappervar config new MapperConfiguration(cfg cfg.CreateMapOrder, OrderDto());// Perform mappingvar mapper config.CreateMapper();OrderDto dto mapper.MapOrder, OrderDto(order);dto.CustomerName.ShouldEqual(George Costanza);dto.Total.ShouldEqual(74.85m);} 可以看到只要设置下Order和OrderDto之间的类型映射就可以了我们看OrderDto中的CustomerName和Total属性在领域模型Order中并没有与之相对性AutoMapper在做解析的时候会按照PascalCase帕斯卡命名法CustomerName其实是由CustomerName 得来的是AutoMapper的一种映射规则而Total是因为在Order中有GetTotal()方法AutoMapper会解析“Get”之后的单词所以会与Total对应。在编写代码过程中可以运用这种规则来定义名称实现自动转换。 Projection Projection可以理解为与Flattening相反Projection是将源对象映射到一个不完全与源对象匹配的目标对象需要制定自定义成员如下面的源对象 public class CalendarEvent{public DateTime EventDate { get; set; }public string Title { get; set; }} 目标对象 public class CalendarEventForm{public DateTime EventDate { get; set; }public int EventHour { get; set; }public int EventMinute { get; set; }public string Title { get; set; }} AutoMapper配置转换代码 public void Example(){// Modelvar calendarEvent new CalendarEvent{EventDate new DateTime(2008, 12, 15, 20, 30, 0),Title Company Holiday Party};var config new MapperConfiguration(cfg {// Configure AutoMappercfg.CreateMapCalendarEvent, CalendarEventForm().ForMember(dest dest.EventDate, opt opt.MapFrom(src src.EventDate.Date)).ForMember(dest dest.EventHour, opt opt.MapFrom(src src.EventDate.Hour)).ForMember(dest dest.EventMinute, opt opt.MapFrom(src src.EventDate.Minute));});// Perform mappingvar mapper config.CreateMapper();CalendarEventForm form mapper.MapCalendarEvent, CalendarEventForm(calendarEvent);form.EventDate.ShouldEqual(new DateTime(2008, 12, 15));form.EventHour.ShouldEqual(20);form.EventMinute.ShouldEqual(30);form.Title.ShouldEqual(Company Holiday Party);}  Configuration Validation 在进行对象映射的时候有可能会出现属性名称或者自定义匹配规则不正确而又没有发现的情况在程序执行时就报错因此AutoMapper提供的AssertConfigurationIsValid()方法来验证结构映射是否正确。  config.AssertConfigurationIsValid();如果映射错误会报“AutoMapperConfigurationException”异常错误就可以进行调试修改了  Lists and Array AutoMapper支持的源集合类型包括 IEnumerableIEnumerableTICollectionICollectionTIListIListTListTArrays有一种情况是在使用集合类型类型的时候类型之间存在继承关系例如下面我们需要转换的类型 //源对象public class ParentSource{public int Value1 { get; set; }}public class ChildSource : ParentSource{public int Value2 { get; set; }}//目标对象public class ParentDestination{public int Value1 { get; set; }}public class ChildDestination : ParentDestination{public int Value2 { get; set; }} AutoMapper需要孩子映射的显式配置AutoMapper配置转换代码 var config new MapperConfiguration(cfg {cfg.CreateMapParentSource, ParentDestination().IncludeChildSource, ChildDestination();cfg.CreateMapChildSource, ChildDestination();});var sources new[]{new ParentSource(),new ChildSource(),new ParentSource()};var destinations config.CreateMapper().MapParentSource[], ParentDestination[](sources);destinations[0].ShouldBeTypeParentDestination();destinations[1].ShouldBeTypeChildDestination();destinations[2].ShouldBeTypeParentDestination(); 注意在Initialize初始化CreateMap进行类型映射配置的时候有个Include泛型方法签名为“Include this configuration in derived types maps”大致意思为包含派生类型中配置ChildSource是ParentSource的派生类ChildDestination是ParentDestination的派生类cfg.CreateMapParentSource, ParentDestination().IncludeChildSource, ChildDestination(); 这段代码是说明ParentSource和ChildSource之间存在的关系并且要要显示的配置。  Nested mappings 嵌套对象映射例如下面的对象        public class OuterSource{public int Value { get; set; }public InnerSource Inner { get; set; }}public class InnerSource{public int OtherValue { get; set; }}//目标对象public class OuterDest{public int Value { get; set; }public InnerDest Inner { get; set; }}public class InnerDest{public int OtherValue { get; set; }} AutoMapper配置转换代码 var config new MapperConfiguration(cfg {cfg.CreateMapOuterSource, OuterDest();cfg.CreateMapInnerSource, InnerDest();});config.AssertConfigurationIsValid();var source new OuterSource{Value 5,Inner new InnerSource {OtherValue 15}};var dest config.CreateMapper().MapOuterSource, OuterDest(source);dest.Value.ShouldEqual(5);dest.Inner.ShouldNotBeNull();dest.Inner.OtherValue.ShouldEqual(15); 对于嵌套映射只要指定下类型映射关系和嵌套类型映射关系就可以了也就是这段代码“Mapper.CreateMapInnerSource, InnerDest();” 其实我们在验证类型映射的时候加上Mapper.AssertConfigurationIsValid(); 这段代码看是不是抛出“AutoMapperMappingException”异常来判断类型映射是否正确。 参考资料 https://github.com/AutoMapper/AutoMapper/wikihttp://www.cnblogs.com/farb/p/AutoMapperContent.html关于AutoMapper陆续更新中...  转载于:https://www.cnblogs.com/yanyangxue2016/p/6229539.html
http://www.pierceye.com/news/197724/

相关文章:

  • 怎么查看网站啥系统做的宁波网站设计制作
  • 温岭手机网站建设合肥企业展厅设计公司
  • 网站建设和制作怎么赚钱外贸网站建设服务器
  • 长沙自动化网站建设瑞安地区建设网站
  • 中山做网站费用网页制作简明教程
  • 芜湖做网站需要多少钱青岛网站建设公司怎么选
  • 塑胶 东莞网站建设企业网络推广培训
  • wordpress五分钟建站手机网站 cms
  • 网站前台后台河南省建设工程质量协会网站
  • wordpress无法拖动小工具长沙seo网站推广
  • 网站的推广方案的内容有哪些网站建设所需技术
  • 手机微网站怎么制作的威特视频网站建设方案
  • 视频播放网站开发的报告潮州网站网站建设
  • 如何查询网站域名备案建设网站找什么问题
  • 南开大学 网站开发技术 刘冲网站排名优化有哪些牛霸天的软件1
  • 高品质网站设计北京市地铁建设管理公司网站
  • 初次建设网站的技巧织梦做分类信息网站
  • 宣讲家网站官网加强作风建设网站业务怎么做的
  • 厚街网站建设价格做办公室的网站
  • 青海做网站找谁wordpress gif缩略图
  • 手机网站全屏显示如何把自己做的网站放到微信上
  • 网站建设云雅淇wordpress
  • 工作室网站需要备案吗python基础教程编程题
  • 建设工程人才招聘信息网站响应式网站 cms
  • 设计签名免费网站福州的网站建设
  • 太原这边有做网站的吗wordpress实现pdf浏览
  • 制作微信公众号的网站开发30岁做网站运营
  • 松江手机网站开发正规免费代理
  • 太原市建设路小学网站昆山住房与城乡建设局网站
  • 石家庄的网站的公司计算机应用技术专业网站开发方向