public void CopyTo() { var copyTo = new CopyToExpression(); //? 为类型“CopyTest”指定代理。 copyTo.Use((profile, type) => { if (type == typeof(CopyToTest)) { return(source => { var copy = (CopyTest)source; return new CopyTest { Id = copy.Id, Name = copy.Name }; }); } return(profile.Create <CopyTest>(type)); }); RuntimeServPools.TryAddSingleton <ICopyToExpression>(() => copyTo); var value = new CopyToTest { Id = 1000, Name = "test", Date = DateTime.Now }; var value2 = new CopyTo2Test { Id = 1000, Name = "test", Date = DateTime.Now }; for (int i = 0; i < 100000; i++) { var copy1 = Mapper.Copy(value); value.Name = "test1"; var copy2 = Mapper.Copy <CopyTest>(value); var copy3 = Mapper.Copy <CopyTest>(value2); value.Name = "test5"; } }
public void MapDisposeTest() { var mapTo = RuntimeServPools.Singleton <IMapToExpression, MapToExpression>(); //? 为类型“CopyTest”指定代理。 mapTo.Run <CopyToTest, MapToTest>(source => { return(new MapToTest { Id = source.Id, Name = source.Name, Date = source.Date }); }); RuntimeServPools.TryAddSingleton(() => mapTo); var t1 = new T1 { A = 100, B = "10000" }; var value = new CopyToTest { Id = 1000, Name = "test", Date = DateTime.Now }; var t2 = Mapper.Map <T2>(t1); using (var map = new MapToExpression()) { var t3 = map.Map <T2>(t1); var map1 = map.Map <MapToTest>(value); var map2 = Mapper.Map <MapToTest>(value); } var map3 = Mapper.Map <MapToTest>(value); }
public void MapTo() { //RuntimeServicePools.TryAdd<IProfileConfiguration, ProfileConfiguration>(); var mapTo = RuntimeServPools.Singleton <IMapToExpression, MapToExpression>(); //? 为类型“CopyTest”指定代理。 mapTo.Run <CopyToTest, MapToTest>(source => { return(new MapToTest { Id = source.Id, Name = source.Name, Date = source.Date }); }); RuntimeServPools.TryAddSingleton(() => mapTo); var t1 = new T1 { A = 100, B = "10000" }; var dic = new Dictionary <string, object> { ["sex"] = 1, ["roleenum"] = 32 }; var user = Mapper.Map <User>(dic); var user2 = new User2 { Role = 32 }; var user3 = Mapper.Map <User>(user2); var user4 = Mapper.Map <User2>(user3); var t2 = Mapper.Map <T2>(t1); var value = new CopyToTest { Id = 1000, Name = "test", Date = DateTime.Now }; for (int i = 0; i < 100000; i++) { //mapTo.MapTo<CopyTest>(value); var map1 = Mapper.Map <CopyTest>(value); value.Name = "test1"; var map2 = Mapper.Map <MapToTest>(value); var map3 = Mapper.Map <IEnumerable <KeyValuePair <string, object> > >(value); var map4 = Mapper.Map <ICollection <KeyValuePair <string, object> > >(value); var map5 = Mapper.Map <IDictionary <string, object> >(value); var map6 = Mapper.Map <Dictionary <string, object> >(value); value.Name = "test5"; } }