using Amazon.DynamoDBv2.Model; using BootCamp.DataAccess.Contract; using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; namespace BootCamp.DataAccess.Extension { public static class PropertyInfoExtensions { /// /// Get the cached property info. /// /// /// /// /// public static PropertyInfo GetCachedProperties(this Dictionary> cache, Type type, string attr) { Dictionary properties; if (!cache.TryGetValue(type, out properties)) { properties = new Dictionary(); foreach (var p in type.GetProperties()) { properties.Add(p.Name, p); } cache.Add(type, properties); } return properties[attr]; } /// /// Get the product dto. /// /// /// /// /// /// public static ProductDto GetProductDto(this Dictionary> cache, Dictionary item, Type dtoType, ProductDto productDto) { foreach (var kvp in item) { try { cache.GetCachedProperties(dtoType, kvp.Key).SetValue(productDto, kvp.Value.S, null); } catch (Exception ex) { Trace.TraceError(ex.ToString()); } } return productDto; } } }