internal IEnumerable <T> MapInternal <T>( ItemsEnumerable items, MappyOptions options, Abbrs abbreviations) { if (_options == null) { _options = MappyOptions.Default; } if (options == null) { options = _options; } if (!options.UseDefaultDictionaryComparer) { items = items .Select(dynamicItem => new Dictionary <string, object>(dynamicItem, options.StringComparer)); } var context = new MappingContext(options, abbreviations); return(options.Cache.GetOrCreateTypeMap <T>(options) .MapList(items.AsList(), null, context)); }
public IEnumerable <T> Map <T>( IEnumerable <dynamic> items, MappyOptions options, Abbrs abbreviations) { return(MapInternal <T>(items, options, abbreviations)); }
internal MappingContext(MappyOptions options, Abbrs abbreviations) { Options = options; TypeConverters = new Dictionary <string, ITypeConverter>( StringComparer.Ordinal); ValuesFields = new Dictionary <int, string[]>(); Abbreviations = abbreviations; }
internal bool HasKeys( MappingContext context, string prefix, Items items, MappyOptions options) { var valueFields = context.GetExistsFieldsForType <T>(prefix, items, options); return(items.Count != 0 && valueFields.Length != 0); }
internal IEnumerable <T> MapInternal <T>( IEnumerable <dynamic> items, MappyOptions options, Abbrs abbreviations) { var dictionary = items .Select(dynamicItem => dynamicItem as IDictionary <string, object>) .Where(x => x != null); return(MapInternal <T>(dictionary, options, abbreviations)); }
public T Map <T>( Items items, MappyOptions options, Abbrs abbreviations) { if (items == null) { throw new ArgumentException("Mapping value should be specified."); } return(MapInternal <T>(new List <Items> { items }, options, abbreviations) .SingleOrDefault()); }
internal string[] GetExistsFieldsForType <T>( string prefix, Items items, MappyOptions options) { var hashCode = HashCode.CombineHashCodes(prefix.GetHashCode(), typeof(T).GetHashCode()); if (!TryGetValueFields(hashCode, out var valueFields)) { valueFields = items .Where(x => x.Key.StartsWith(prefix, options.StringComparison)) .Select(x => x.Key) .ToArray(); AddValueFields(hashCode, valueFields); } return(valueFields); }
internal bool HasValues( MappingContext context, string prefix, Items items, MappyOptions options) { var valueFields = context.GetExistsFieldsForType <T>(prefix, items, options); if (items.Count == 0) { return(false); } foreach (var field in valueFields) { if (items[field] != null) { return(true); } } return(false); }
public IEnumerable <T> Map <T>( ItemsEnumerable items, MappyOptions options) { return(Map <T>(items, options, null)); }
public T Map <T>( Items items, MappyOptions options) { return(Map <T>(items, options, null)); }
public IEnumerable <T> Map <T>( IEnumerable <dynamic> items, MappyOptions options) { return(Map <T>(items, options, null)); }
public Mappy(MappyOptions options = null) { _options = options ?? MappyOptions.Default; }