/// <summary> /// Given a POCO, converts it to an Amazon ReplaceableItem /// </summary> /// <typeparam name="T">Type converting from</typeparam> /// <param name="item">Item to convert</param> /// <returns></returns> public virtual ReplaceableItem Convert <T>(T item) { // Obtain the entity map to work with var map = _entityMapper.CreateMap <T>(); // Convert the properties var itemName = GetPropertyValue(item, map.KeyProperty); var attributes = GetReplaceableAttributes(item, map); // Create the item return(new ReplaceableItem() .WithItemName(itemName) .WithAttribute(attributes)); }
/// <summary> /// Converts an an Amazon SimpleDB Item into an instance to type T /// </summary> /// <typeparam name="T">Type to convert to</typeparam> /// <param name="item">SimpleDB Item to read from</param> /// <returns></returns> public virtual T Convert <T>(Item item) where T : new() { var instance = new T(); // Obtain the entity map to work with var map = _entityMapper.CreateMap <T>(); var attributeDictionary = item.Attribute.ToLookup(a => a.Name); // Set the properties SetProperty(item.Name, instance, map.KeyProperty); map.PersistableProperties .AsParallel() .Each(p => attributeDictionary .Where(a => a.Key == p.Name) .AsParallel() .Each(a => SetProperty(GetFullValue(a), instance, p)) ); return(instance); }