Esempio n. 1
0
        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));
        }
Esempio n. 2
0
 public IEnumerable <T> Map <T>(
     IEnumerable <dynamic> items,
     MappyOptions options,
     Abbrs abbreviations)
 {
     return(MapInternal <T>(items, options, abbreviations));
 }
Esempio n. 3
0
 internal MappingContext(MappyOptions options, Abbrs abbreviations)
 {
     Options        = options;
     TypeConverters = new Dictionary <string, ITypeConverter>(
         StringComparer.Ordinal);
     ValuesFields  = new Dictionary <int, string[]>();
     Abbreviations = abbreviations;
 }
Esempio n. 4
0
        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);
        }
Esempio n. 5
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));
        }
Esempio n. 6
0
 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());
 }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
 public IEnumerable <T> Map <T>(
     ItemsEnumerable items,
     MappyOptions options)
 {
     return(Map <T>(items, options, null));
 }
Esempio n. 10
0
 public T Map <T>(
     Items items,
     MappyOptions options)
 {
     return(Map <T>(items, options, null));
 }
Esempio n. 11
0
 public IEnumerable <T> Map <T>(
     IEnumerable <dynamic> items,
     MappyOptions options)
 {
     return(Map <T>(items, options, null));
 }
Esempio n. 12
0
 public Mappy(MappyOptions options = null)
 {
     _options = options ?? MappyOptions.Default;
 }