public static IReadOnlyList <T> WrapAsIReadOnlyList <T>(this IEnumerable <T> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (source is T[] array)
            {
#if LESSTHAN_NET45
                return(new ReadOnlyCollectionEx <T>(array));
#else
                return(ArrayEx.AsReadOnly(array));
#endif
            }
            if (source is ListEx <T> listEx)
            {
                return(listEx.AsReadOnly());
            }
#if GREATERTHAN_NET45 || TARGETS_NETCORE || TARGETS_NETSTANDARD
            if (source is List <T> list)
            {
                return(list.AsReadOnly());
            }
#endif
            if (source is IReadOnlyList <T> result)
            {
                return(result);
            }
            return(EnumerationList <T> .Create(source));
        }
        public static IReadOnlyCollection <T> AsIReadOnlyCollection <T>(this IEnumerable <T>?source)
        {
            if (source == null)
            {
                return(EmptyCollection <T> .Instance);
            }
            if (source is T[] array)
            {
#if LESSTHAN_NET45
                return(new ReadOnlyCollectionEx <T>(array));
#else
                return(ArrayEx.AsReadOnly(array));
#endif
            }
            if (source is ListEx <T> listEx)
            {
                return(listEx.AsReadOnly());
            }
#if GREATERTHAN_NET45 || TARGETS_NETCORE || TARGETS_NETSTANDARD
            if (source is List <T> list)
            {
                return(list.AsReadOnly());
            }
#endif
            if (source is IReadOnlyCollection <T> result)
            {
                return(result);
            }
            return(EnumerationList <T> .Create(source));
        }
示例#3
0
        public EnumerationFinder(List <T> samples)
        {
            Collection      = samples.AsQueryable();
            EnumerationList = new EnumerationList();
            Schema          = SchemaFinder <T> .GenerateSchema();

            EnumerationList.Enumerations = new Dictionary <string, List <dynamic> >();
        }
示例#4
0
 protected ProgressiveLookup(Progressor <IGrouping <TKey, T> > progressor, IDictionary <TKey, IGrouping <TKey, T> > cache, IEqualityComparer <TKey> keyComparer, IEqualityComparer <T> itemComparer)
 {
     _cache        = cache ?? throw new ArgumentNullException(nameof(cache));
     Progressor    = progressor ?? throw new ArgumentNullException(nameof(progressor));
     _subscription = Progressor.SubscribeAction(obj => _cache.Add(new KeyValuePair <TKey, IGrouping <TKey, T> >(obj.Key, obj)));
     KeyComparer   = keyComparer ?? EqualityComparer <TKey> .Default;
     ItemComparer  = itemComparer ?? EqualityComparer <T> .Default;
     Keys          = new EnumerationList <TKey>(this.ConvertProgressive(input => input.Key));
 }
 public static ICollection <T> AsICollection <T>(this IEnumerable <T>?source)
 {
     if (source == null)
     {
         return(ArrayEx.Empty <T>());
     }
     if (source is ICollection <T> collection)
     {
         return(collection);
     }
     return(EnumerationList <T> .Create(source));
 }
 public static IList <T> WrapAsIList <T>(this IEnumerable <T> source)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     if (source is IList <T> list)
     {
         return(list);
     }
     return(EnumerationList <T> .Create(source));
 }
        public static PackedData Compress(ICollection <T> collection, Schema schema, EnumerationList enumerationList)
        {
            PackedData packedData = new PackedData();

            packedData.EnumerationList = enumerationList;
            packedData.PData           = new List <Dictionary <string, dynamic> >();

            var enumerationIndexMap = enumerationList.GenerateKeyMap();

            foreach (var item in collection)
            {
                Dictionary <string, dynamic> pItem = new Dictionary <string, dynamic>();
                foreach (var keyVal in schema.KeyMap)
                {
                    PropertyInfo propInfo  = keyVal.Value.Property;
                    dynamic      itemValue = propInfo.GetValue(item);
                    var          newKey    = schema.KeyMap[keyVal.Key].NewKey;
                    if (enumerationIndexMap.ContainsKey(newKey))
                    {
                        var enumMapping = enumerationIndexMap[newKey];
                        if (itemValue == null)
                        {
                            pItem.Add(newKey, 0); //NULL has a predefined index value of 0
                        }
                        else
                        {
                            pItem.Add(newKey, enumMapping[itemValue]);
                        }
                    }
                    else
                    {
                        pItem.Add(keyVal.Value.NewKey, itemValue);
                    }
                }
                packedData.PData.Add(pItem);
            }

            return(packedData);
        }
示例#8
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method disposes of resources in the model.</summary>
        ///--------------------------------------------------------------------------------
        protected override void OnDispose()
        {
            if (ReverseInstance != null)
            {
                ReverseInstance.Dispose();
                ReverseInstance = null;
            }
            if (ForwardInstance != null)
            {
                ForwardInstance.Dispose();
                ForwardInstance = null;
            }
            Solution = null;
            Solution = null;
            if (_enumerationList != null)
            {
                foreach (Enumeration item in EnumerationList)
                {
                    item.Dispose();
                }
                EnumerationList.Clear();
                EnumerationList = null;
            }
            if (_modelObjectList != null)
            {
                foreach (ModelObject item in ModelObjectList)
                {
                    item.Dispose();
                }
                ModelObjectList.Clear();
                ModelObjectList = null;
            }

            #region protected
            #endregion protected

            base.OnDispose();
        }
        public static IList <T> AsIList <T>(this IEnumerable <T>?source)
        {
            if (source == null)
            {
                return(ArrayEx.Empty <T>());
            }
            if (source is IList <T> list)
            {
                return(list);
            }
            if (source is ICollection <T> collection)
            {
                if (collection.Count == 0)
                {
                    return(ArrayEx.Empty <T>());
                }

                var result = new T[collection.Count];
                collection.CopyTo(result, 0);
                return(result);
            }
            return(EnumerationList <T> .Create(source));
        }