|
6 | 6 | using SharpRepository.Repository; |
7 | 7 | using SharpRepository.Repository.Caching; |
8 | 8 | using SharpRepository.Repository.FetchStrategies; |
| 9 | +using SharpRepository.Repository.Helpers; |
9 | 10 |
|
10 | 11 | namespace SharpRepository.CacheRepository |
11 | 12 | { |
@@ -72,11 +73,13 @@ private static IEnumerable<T> CloneDictionary(ConcurrentDictionary<string, T> li |
72 | 73 |
|
73 | 74 | foreach (var keyValuePair in list) |
74 | 75 | { |
75 | | - var newItem = new T(); |
76 | | - foreach (var propInfo in properties) |
77 | | - { |
78 | | - propInfo.SetValue(newItem, propInfo.GetValue(keyValuePair.Value, null), null); |
79 | | - } |
| 76 | + //var newItem = new T(); |
| 77 | + //foreach (var propInfo in properties) |
| 78 | + //{ |
| 79 | + // propInfo.SetValue(newItem, propInfo.GetValue(keyValuePair.Value, null), null); |
| 80 | + //} |
| 81 | + //use new deep clone by lambda compiler to improved performance most. |
| 82 | + var newItem = keyValuePair.Value.DeepClone(); |
80 | 83 |
|
81 | 84 | clonedList.Add(newItem); |
82 | 85 | } |
@@ -206,18 +209,22 @@ private static IEnumerable<T> CloneDictionary(ConcurrentDictionary<CompoundKey, |
206 | 209 | // when you Google deep copy of generic list every answer uses either the IClonable interface on the T or having the T be Serializable |
207 | 210 | // since we can't really put those constraints on T I'm going to do it via reflection |
208 | 211 |
|
209 | | - var type = typeof(T); |
210 | | - var properties = type.GetProperties(); |
| 212 | + //var type = typeof(T); |
| 213 | + //var properties = type.GetProperties(); |
211 | 214 |
|
212 | 215 | var clonedList = new List<T>(list.Count); |
213 | 216 |
|
214 | 217 | foreach (var keyValuePair in list) |
215 | 218 | { |
216 | | - var newItem = new T(); |
217 | | - foreach (var propInfo in properties) |
218 | | - { |
219 | | - propInfo.SetValue(newItem, propInfo.GetValue(keyValuePair.Value, null), null); |
220 | | - } |
| 219 | + //var newItem = new T(); |
| 220 | + //foreach (var propInfo in properties) |
| 221 | + //{ |
| 222 | + // // Don't try and set a value to a property w/o a setter |
| 223 | + // if (propInfo.CanWrite) |
| 224 | + // propInfo.SetValue(newItem, propInfo.GetValue(keyValuePair.Value, null), null); |
| 225 | + //} |
| 226 | + //use new deep clone by lambda compiler to improved performance most. |
| 227 | + var newItem = keyValuePair.Value.DeepClone(); |
221 | 228 |
|
222 | 229 | clonedList.Add(newItem); |
223 | 230 | } |
@@ -343,18 +350,22 @@ private static IEnumerable<T> CloneDictionary(ConcurrentDictionary<CompoundKey, |
343 | 350 | // when you Google deep copy of generic list every answer uses either the IClonable interface on the T or having the T be Serializable |
344 | 351 | // since we can't really put those constraints on T I'm going to do it via reflection |
345 | 352 |
|
346 | | - var type = typeof(T); |
347 | | - var properties = type.GetProperties(); |
| 353 | + //var type = typeof(T); |
| 354 | + //var properties = type.GetProperties(); |
348 | 355 |
|
349 | 356 | var clonedList = new List<T>(list.Count); |
350 | 357 |
|
351 | 358 | foreach (var keyValuePair in list) |
352 | 359 | { |
353 | | - var newItem = new T(); |
354 | | - foreach (var propInfo in properties) |
355 | | - { |
356 | | - propInfo.SetValue(newItem, propInfo.GetValue(keyValuePair.Value, null), null); |
357 | | - } |
| 360 | + //var newItem = new T(); |
| 361 | + //foreach (var propInfo in properties) |
| 362 | + //{ |
| 363 | + // // Don't try and set a value to a property w/o a setter |
| 364 | + // if (propInfo.CanWrite) |
| 365 | + // propInfo.SetValue(newItem, propInfo.GetValue(keyValuePair.Value, null), null); |
| 366 | + //} |
| 367 | + //use new deep clone by lambda compiler to improved performance most. |
| 368 | + var newItem = keyValuePair.Value.DeepClone(); |
358 | 369 |
|
359 | 370 | clonedList.Add(newItem); |
360 | 371 | } |
@@ -450,17 +461,21 @@ private static IEnumerable<T> CloneDictionary(ConcurrentDictionary<CompoundKey, |
450 | 461 | // when you Google deep copy of generic list every answer uses either the IClonable interface on the T or having the T be Serializable |
451 | 462 | // since we can't really put those constraints on T I'm going to do it via reflection |
452 | 463 |
|
453 | | - var type = typeof(T); |
454 | | - var properties = type.GetProperties(); |
| 464 | + //var type = typeof(T); |
| 465 | + //var properties = type.GetProperties(); |
455 | 466 | var clonedList = new List<T>(list.Count); |
456 | 467 |
|
457 | 468 | foreach (var keyValuePair in list) |
458 | 469 | { |
459 | | - var newItem = new T(); |
460 | | - foreach (var propInfo in properties) |
461 | | - { |
462 | | - propInfo.SetValue(newItem, propInfo.GetValue(keyValuePair.Value, null), null); |
463 | | - } |
| 470 | + //var newItem = new T(); |
| 471 | + //foreach (var propInfo in properties) |
| 472 | + //{ |
| 473 | + // // Don't try and set a value to a property w/o a setter |
| 474 | + // if (propInfo.CanWrite) |
| 475 | + // propInfo.SetValue(newItem, propInfo.GetValue(keyValuePair.Value, null), null); |
| 476 | + //} |
| 477 | + //use new deep clone by lambda compiler to improved performance most. |
| 478 | + var newItem = keyValuePair.Value.DeepClone(); |
464 | 479 |
|
465 | 480 | clonedList.Add(newItem); |
466 | 481 | } |
|
0 commit comments