当前位置: 首页>>代码示例>>C#>>正文


C# MemberMapper.ClearMapCache方法代码示例

本文整理汇总了C#中MemberMapper.ClearMapCache方法的典型用法代码示例。如果您正苦于以下问题:C# MemberMapper.ClearMapCache方法的具体用法?C# MemberMapper.ClearMapCache怎么用?C# MemberMapper.ClearMapCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MemberMapper的用法示例。


在下文中一共展示了MemberMapper.ClearMapCache方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ClearMapCacheIsRespected

        public void ClearMapCacheIsRespected()
        {
            var mapper = new MemberMapper();

              mapper.CreateMap<SourceType, DestinationType>(customMapping: src => new
              {
            ID = src.ID * 10,
            Name = src.Name + src.Name
              });

              var source = new SourceType
              {
            ID = 10,
            Name = "x"
              };

              var result = mapper.Map<DestinationType>(source);

              Assert.AreEqual(100, result.ID);
              Assert.AreEqual("xx", result.Name);

              mapper.ClearMapCache();

              result = mapper.Map<DestinationType>(source);

              Assert.AreEqual(10, result.ID);
              Assert.AreEqual("x", result.Name);
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:28,代码来源:MemberMapperTests.cs

示例2: CreateMapIsThreadSafe

        public void CreateMapIsThreadSafe()
        {
            var mapper = new MemberMapper();

              var thread1 = new Thread(() =>
              {
            while (true)
            {
              var map = mapper.CreateMap<Source, Destination>();

              var result = map.MappingFunction(new Source { Foo = 1 }, new Destination());

              Assert.AreEqual(1, result.Foo);

              mapper.ClearMapCache();
            }
              });

              var thread2 = new Thread(() =>
              {
            while (true)
            {
              var map = mapper.CreateMap<Source, Destination>();

              var result = map.MappingFunction(new Source { Foo = 1 }, new Destination());

              Assert.AreEqual(1, result.Foo);

              mapper.ClearMapCache();
            }
              });

              thread1.Start();
              thread2.Start();

              Thread.Sleep(2000);

              thread1.Abort();
              thread2.Abort();
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:40,代码来源:ThreadSafetyTests.cs

示例3: DirectMapping

        public static void DirectMapping()
        {
            var customer = new Customer
              {
            ID = 1,
            FirstName = "First",
            LastName = "Last",
            Orders = new List<Order>
            {
              new Order
              {
            ID = 1,
            Amount = 10,
              },
              new Order
              {
            ID = 2,
            Amount = 20
              }
            }
              };

              var mapper = new MemberMapper();

              // Explicit source and destination type, just pass a source type instance
              var dto = mapper.Map<Customer, CustomerDto>(customer);

              // Just specify what ThisMember should map to, pass in any type that you think can be mapped
              dto = mapper.Map<CustomerDto>(customer);

              // Update the existing Customer, just set a new FirstName for him
              dto = new CustomerDto
              {
            FirstName = "NewName"
              };

              // For that we have to set an option that null-values from the source are ignored, so that LastName does not get set to null
              mapper.Options.Conventions.IgnoreMembersWithNullValueOnSource = true;

              // Setting an option that affects map generation has no effect on maps that have already been generated. Normally there'd be little
              // need to set this option on the fly, you would just have a seperate mapper for doing these mappings. But for this sample, it works fine.
              mapper.ClearMapCache(); // We could also have called mapper.CreateMap<CustomerDto, Customer>(), which always recreates the map.

              // Only FirstName will have changed now on customer, because the null (or null-equivalent in case of nullable value types) values were ignored.
              mapper.Map(dto, customer);
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:46,代码来源:SimpleScenarios.cs


注:本文中的MemberMapper.ClearMapCache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。