System.Collections.Generic.ICollection.Add(T)

Here are the examples of the csharp api System.Collections.Generic.ICollection.Add(T) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

714 Examples 7

19 Source : CollectionExtension.cs
with MIT License
from AlphaYu

public static void AddRangeIfNotContains<T>([NotNull] this ICollection<T> @this, params T[] values)
        {
            if (@this.IsReadOnly) return;
            foreach (var value in values)
            {
                if ([email protected](value))
                {
                    @this.Add(value);
                }
            }
        }

19 Source : IEnumerableExtensions.cs
with MIT License
from AlphaYu

public static void AddRange<T>(this ICollection<T> @this, params T[] values)
        {
            foreach (var obj in values)
            {
                @this.Add(obj);
            }
        }

19 Source : IEnumerableExtensions.cs
with MIT License
from AlphaYu

public static void AddRangeIf<T>(this ICollection<T> @this, Func<T, bool> predicate, params T[] values)
        {
            foreach (var obj in values)
            {
                if (predicate(obj))
                {
                    @this.Add(obj);
                }
            }
        }

19 Source : IEnumerableExtensions.cs
with MIT License
from AlphaYu

public static void AddRangeIfNotContains<T>(this ICollection<T> @this, params T[] values)
        {
            foreach (T obj in values)
            {
                if ([email protected](obj))
                {
                    @this.Add(obj);
                }
            }
        }

19 Source : IEnumerableExtensions.cs
with MIT License
from AlphaYu

public static void InsertAfter<T>(this IList<T> list, Func<T, bool> condition, T value)
        {
            foreach (var item in list.Select((item, index) => new { item, index }).Where(p => condition(p.item)).OrderByDescending(p => p.index))
            {
                if (item.index + 1 == list.Count)
                {
                    list.Add(value);
                }
                else
                {
                    list.Insert(item.index + 1, value);
                }
            }
        }

19 Source : IEnumerableExtensions.cs
with MIT License
from AlphaYu

public static void InsertAfter<T>(this IList<T> list, int index, T value)
        {
            foreach (var item in list.Select((v, i) => new { Value = v, Index = i }).Where(p => p.Index == index).OrderByDescending(p => p.Index))
            {
                if (item.Index + 1 == list.Count)
                {
                    list.Add(value);
                }
                else
                {
                    list.Insert(item.Index + 1, value);
                }
            }
        }

19 Source : CollectionHelper.cs
with MIT License
from ambleside138

public static void AddRange<T>(this ICollection<T> addTo, IEnumerable<T> source)
        {
            foreach(var item in source)
            {
                addTo.Add(item);
            }
        }

19 Source : ObservableCollectionEx.cs
with GNU General Public License v3.0
from Amebis

public void AddRange(IEnumerable<T> range)
        {
            foreach (var item in range)
                Items.Add(item);
            EndUpdate();
        }

19 Source : ObservableCollectionEx.cs
with GNU General Public License v3.0
from Amebis

public void Reset(T el)
        {
            Items.Clear();
            Items.Add(el);
            EndUpdate();
        }

19 Source : IEnumerableExtensions.cs
with GNU General Public License v3.0
from andysal

public static ICollection<T> GetCollection<T>(this IEnumerable<T> data)
        {
            ICollection<T> internalColl = Activator.CreateInstance<ICollection<T>>();

            foreach (T value in data)
            {
                //if (predicate(value)) yield return value;
                internalColl.Add(value);
            }

            return internalColl;
        }

19 Source : CollectionExtensions.cs
with MIT License
from AngleSharp

public static void AddRange<T>(this ICollection<T> target, IEnumerable<T> source)
        {
            if (target is null)
                throw new ArgumentNullException(nameof(target));
            if (source is null)
                throw new ArgumentNullException(nameof(source));

            foreach (var item in source)
            {
                target.Add(item);
            }
        }

19 Source : AddObjectsOperation.cs
with MIT License
from AnnoDesigner

protected override void RedoOperation()
        {
            foreach (var obj in Objects)
            {
                Collection.Add(obj);
            }
        }

19 Source : RemoveObjectsOperation.cs
with MIT License
from AnnoDesigner

protected override void UndoOperation()
        {
            foreach (var obj in Objects)
            {
                Collection.Add(obj);
            }
        }

19 Source : TopologicalSort.cs
with MIT License
from ansel86castro

public static int Visit<T>(T item, Func<T, IEnumerable<T>> getDependencies, List<ICollection<T>> sorted, Dictionary<T, int> visited, bool ignoreCycles)
        {
            const int inProcess = -1;
            int level;
            var alreadyVisited = visited.TryGetValue(item, out level);

            if (alreadyVisited)
            {
                if (level == inProcess && ignoreCycles)
                {
                    throw new ArgumentException("Cyclic dependency found.");
                }
            }
            else
            {
                visited[item] = level = inProcess;

                var dependencies = getDependencies(item);
                if (dependencies != null)
                {
                    foreach (var dependency in dependencies)
                    {
                        var depLevel = Visit(dependency, getDependencies, sorted, visited, ignoreCycles);
                        level = Math.Max(level, depLevel);
                    }
                }

                visited[item] = ++level;
                while (sorted.Count <= level)
                {
                    sorted.Add(new Collection<T>());
                }
                sorted[level].Add(item);
            }

            return level;
        }

19 Source : IThreadSafeList.cs
with GNU General Public License v3.0
from anydream

public static void Add_NoLock<T>(this ICollection<T> list, T item) {
#if THREAD_SAFE
			var tsList = list as ThreadSafe.IList<T>;
			if (tsList != null)
				tsList.Add_NoLock(item);
			else
#endif
				list.Add(item);
		}

19 Source : Matrix.cs
with GNU Lesser General Public License v3.0
from ApexGameTools

public void GetRange(int fromColumn, int toColumn, int fromRow, int toRow, ICollection<T> result)
        {
            var startColumn = AdjustColumnToBounds(fromColumn);
            var endColumn = AdjustColumnToBounds(toColumn);

            var startRow = AdjustRowToBounds(fromRow);
            var endRow = AdjustRowToBounds(toRow);

            for (int x = startColumn; x <= endColumn; x++)
            {
                for (int z = startRow; z <= endRow; z++)
                {
                    result.Add(_matrix[x, z]);
                }
            }
        }

19 Source : SharedExtensions.cs
with GNU Lesser General Public License v3.0
from ApexGameTools

public static void AddRange<T>(this ICollection<T> list, IEnumerable<T> items)
        {
            foreach (var item in items)
            {
                list.Add(item);
            }
        }

19 Source : Matrix.cs
with GNU Lesser General Public License v3.0
from ApexGameTools

public void GetRange(int fromColumn, int toColumn, int fromRow, int toRow, Func<T, bool> predicate, ICollection<T> result)
        {
            var startColumn = AdjustColumnToBounds(fromColumn);
            var endColumn = AdjustColumnToBounds(toColumn);

            var startRow = AdjustRowToBounds(fromRow);
            var endRow = AdjustRowToBounds(toRow);

            for (int x = startColumn; x <= endColumn; x++)
            {
                for (int z = startRow; z <= endRow; z++)
                {
                    var item = _matrix[x, z];
                    if (predicate(item))
                    {
                        result.Add(item);
                    }
                }
            }
        }

19 Source : SharedExtensions.cs
with GNU Lesser General Public License v3.0
from ApexGameTools

public static bool AddUnique<T>(this IList<T> list, T item)
        {
            if (!list.Contains(item))
            {
                list.Add(item);
                return true;
            }

            return false;
        }

19 Source : DelayedList.cs
with MIT License
from ArchonInteractive

public void ProcessPending()
        {
            var changeCount = _changeQueue.Count;
            for (var i = 0; i < changeCount; i++)
            {
                var change = _changeQueue.Dequeue();

                switch (change.Action)
                {
                    case Action.Add:
                        _items.Add(change.Value);
                        break;
                    case Action.Remove:
                        _items.Remove(change.Value);
                        break;
                    case Action.Clear:
                        _items.Clear();
                        break;
                }
            }
        }

19 Source : MahjongLogic.cs
with MIT License
from ArcturusZhang

private static void CombinationBackTrack<T>(IList<T> list, int count, int start, IList<T> current, IList<List<T>> result)
        {
            // exits
            if (current.Count == count)
            {
                result.Add(new List<T>(current));
                return;
            }
            for (int i = start; i < list.Count; i++)
            {
                current.Add(list[i]);
                CombinationBackTrack(list, count, i + 1, current, result);
                // back track
                current.RemoveAt(current.Count - 1);
            }
        }

19 Source : ObservableDictionary.cs
with GNU General Public License v3.0
from Artentus

public void Add(T item) => _baseCollection.Add(item);

19 Source : SmartCollection.cs
with MIT License
from aspnetde

public void AddRange(IEnumerable<T> range)
        {
            foreach (var item in range)
            {
                Items.Add(item);
            }

            OnPropertyChanged(new PropertyChangedEventArgs("Count"));
            OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }

19 Source : Utils.cs
with GNU Lesser General Public License v3.0
from autocore-ai

public static void TryAdd<T>(this ICollection<T> collection, T target)
        {
            if (!collection.Contains(target))
            {
                collection.Add(target);
            }
        }

19 Source : FileUtility.cs
with GNU General Public License v3.0
from autodotua

public static T GetFileTree<T>(Project project,
        IEnumerable<T> files,
        Func<File, T> getNewItem,
        Func<T, File> getFile,
        Func<T, IList<T>> getSubFiles,
        Action<T, T> setParent
        ) where T : clreplaced
        {
            Dictionary<T, Queue<string>> fileDirs = new Dictionary<T, Queue<string>>();
            T root = getNewItem(new File() { Dir = "", Project = project });

            foreach (var file in files)
            {
                if (string.IsNullOrEmpty(getFile(file).Dir))
                {
                    //位于根目录
                    getSubFiles(root).Add(file);
                }
                else
                {
                    string[] dirs = getFile(file).Dir.Split('/', '\\');
                    if (getFile(file).IsFolder)
                    {
                        //如果是文件夹,那么层级上需要减少最后一个目录级别,
                        //因为最后一个目录级别就是文件夹本身
                        string[] newDirs = new string[dirs.Length - 1];
                        Array.Copy(dirs, newDirs, newDirs.Length);
                        dirs = newDirs;
                    }
                    var current = root;
                    string path = "";
                    foreach (var dir in dirs)
                    {
                        //dir是单个层级的名称,File.Dir是路径名,因此需要进行连接
                        if (path.Length == 0)
                        {
                            path += dir;
                        }
                        else
                        {
                            path += "\\" + dir;
                        }
                        if (getSubFiles(current).FirstOrDefault(p => getFile(p).Dir == path) is T sub)
                        {
                            //如果是已经存在的子目录,那么直接获取
                            current = sub;
                        }
                        else
                        {
                            sub = getNewItem(new File() { Dir = path, Project = project });
                            getSubFiles(current).Add(sub);
                            setParent(sub, current);
                            current = sub;
                        }
                    }
                    getSubFiles(current).Add(file);
                    setParent(file, current);
                }
            }
            return root;
        }

19 Source : ExtensionMethods.cs
with MIT License
from AvaloniaUI

public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> elements)
        {
            foreach (T e in elements)
                collection.Add(e);
        }

19 Source : CosmosDbValueQuery.cs
with MIT License
from Avanade

public void SelectQuery<TColl>(TColl coll) where TColl : ICollection<T>
        {
            ExecuteQuery(query => 
            {
                foreach (var item in query.Paging(QueryArgs.Paging).AsEnumerable())
                {
                    coll.Add(_container.GetValue(item));
                }

                if (QueryArgs.Paging != null && QueryArgs.Paging.IsGetCount)
                    QueryArgs.Paging.TotalCount = query.Count();
            });
        }

19 Source : EfDbQuery.cs
with MIT License
from Avanade

public void SelectQuery<TColl>(TColl coll) where TColl : ICollection<T>
        {
            ExecuteQuery(query =>
            {
                var q = SetPaging(query, Args.Paging);

                foreach (var item in q)
                {
                    coll.Add(MapToSrce(item) ?? throw new InvalidOperationException("Mapping from the EF enreplacedy must not result in a null value."));
                }

                if (Args.Paging != null && Args.Paging.IsGetCount)
                    Args.Paging.TotalCount = query.LongCount();
            });
        }

19 Source : ODataQuery.cs
with MIT License
from Avanade

public void SelectQuery<TColl>(TColl coll) where TColl : ICollection<T>
        {
            ExecuteQuery(q =>
            {
                ODataFeedAnnotations ann = null!;

                if (QueryArgs.Paging != null)
                {
                    q = q.Skip(QueryArgs.Paging.Skip).Top(QueryArgs.Paging.Take);
                    if (QueryArgs.Paging.IsGetCount && _odata.IsPagingGetCountSupported)
                        ann = new ODataFeedAnnotations();
                }

                foreach (var item in q.FindEntriesAsync(ann).GetAwaiter().GetResult())
                {
                    coll.Add(ODataBase.GetValue<T, TModel>(QueryArgs, item)!);
                }

                if (ann != null)
                    QueryArgs.Paging!.TotalCount = ann.Count;
            });
        }

19 Source : ListExtensions.cs
with MIT License
from AximoGames

public static void AddRange<T>(this IList<T> list, ICollection<T> items)
        {
            if (list is List<T> l)
            {
                l.AddRange(items);
                return;
            }

            foreach (var itm in items)
                list.Add(itm);
        }

19 Source : MeshComponent{T}.cs
with MIT License
from AximoGames

public int Add(T value)
        {
            Values.Add(value);
            return Values.Count - 1;
        }

19 Source : MeshComponent{T}.cs
with MIT License
from AximoGames

public void SetLength(int length)
        {
            var sizeDiff = length - Values.Count;
            for (var i = 0; i < sizeDiff; i++)
                Values.Add(default(T));
        }

19 Source : BixReader.cs
with MIT License
from azist

public TCollection ReadCollection<TCollection, T>(Func<BixReader, T> read) where TCollection : clreplaced, ICollection<T>, new()
    {
      if (!ReadBool()) return null;

      var len = ReadUint();
      if (len > Format.MAX_COLLECTION_LEN)
        throw new BixException(StringConsts.BIX_READ_X_ARRAY_MAX_SIZE_ERROR.Args(len, typeof(T).Name, Format.MAX_COLLECTION_LEN));

      var result = new TCollection();

      for (int i = 0; i < len; i++)
      {
        var elm = read(this);
        result.Add(elm);
      }

      return result;
    }

19 Source : IListExt.cs
with MIT License
from baba-s

public static void FillBy<T>( this IList<T> list, Func<int, T> func, int count )
		{
			int listcount = list.Count;
			for ( int i = 0; i < count; i++ )
			{
				if ( i < listcount )
				{
					list[ i ] = func( i );
				}
				else
				{
					list.Add( func( i ) );
				}
			}
		}

19 Source : IListExt.cs
with MIT License
from baba-s

public static void FillBy<T>( this IList<T> list, T value, int count )
		{
			int listcount = list.Count;
			for ( int i = 0; i < count; i++ )
			{
				if ( i < listcount )
				{
					list[ i ] = value;
				}
				else
				{
					list.Add( value );
				}
			}
		}

19 Source : ListExtensions.cs
with The Unlicense
from BAndysc

public static void OverrideWith<T>(this IList<T> that, IList<T> with)
        {
            int i = 0;
            foreach (var r in with)
            {
                if (i < that.Count)
                    that[i] = r;
                else
                    that.Add(r);

                i++;
            }
            while (that.Count > i)
            {
                that.RemoveAt(that.Count - 1);
            }
        }

19 Source : CollectionMapper.cs
with MIT License
from barnardos-au

public IEnumerable MapValues(IEnumerable fromList, Type toInstanceOfType)
        {
            var to = (ICollection<T>)TranslateListWithElements<T>.CreateInstance(toInstanceOfType);
            foreach (var item in fromList)
            {
                to.Add(ValueMapper.MapValue<T>(item));
            }
            return to;
        }

19 Source : EnumerableExtensions.cs
with MIT License
from bbepis

public static void AddRange<T>( this ICollection<T> collection, IEnumerable<T> values )
      {
         foreach( var value in values )
         {
            collection.Add( value );
         }
      }

19 Source : CollectionExtensions.cs
with MIT License
from BEagle1984

public static void ThreadSafeAdd<T>(this ICollection<T> collection, T item)
        {
            lock (collection)
            {
                collection.Add(item);
            }
        }

19 Source : CommonlyHelper.cs
with Apache License 2.0
from BeiYinZhiNian

public static void TreeToList<T>(this IList<T> data,IList<T> list) where T : clreplaced, ITree<T>
        {
            foreach (var item in data)
            {
                list.Add(item);
                if (item.Children!=null && item.Children.Count > 0)
                {
                    TreeToList(item.Children,list);
                }
            }
        }

19 Source : CommonlyHelper.cs
with Apache License 2.0
from BeiYinZhiNian

public static void TreeToList<T>(this T data, IList<T> list,bool needParent = true) where T : clreplaced, ITree<T>
        {
            if (list == null)
            {
                list = new List<T>();
            }
            if (list.Count == 0 && needParent)
            {
                list.Add(data);
            }
            foreach (var item in data.Children)
            {
                list.Add(item);
                if (item.Children != null && item.Children.Count > 0)
                {
                    TreeToList(item, list, needParent);
                }
            }
        }

19 Source : CommonlyHelper.cs
with Apache License 2.0
from BeiYinZhiNian

public static void TreeToList<T>(this T data, IList<T> list,bool needParent = true) where T : clreplaced, ITree<T>
        {
            if (list == null)
            {
                list = new List<T>();
            }
            if (list.Count == 0 && needParent)
            {
                list.Add(data);
            }
            foreach (var item in data.Children)
            {
                list.Add(item);
                if (item.Children != null && item.Children.Count > 0)
                {
                    TreeToList(item, list, needParent);
                }
            }
        }

19 Source : EnumerableIList.cs
with Apache License 2.0
from benaadams

public void Add(T item) => _list.Add(item);

19 Source : SOSet.cs
with MIT License
from bengreenier

public void Add(T thing)
        {
            if (!Items.Contains(thing))
                Items.Add(thing);
        }

19 Source : EnumerableIList.cs
with GNU Lesser General Public License v3.0
from BepInEx

public void Add(T item)
        {
            _list.Add(item);
        }

19 Source : ListLocalMemoryBase.cs
with MIT License
from bing-framework

public virtual bool Add(T item)
        {
            if (Exists(item))
                return false;
            lock (GetSyncCache())
            {
                GetCache().Add(item);
                return true;
            }
        }

19 Source : DependencyOrderingUtility.cs
with BSD 3-Clause "New" or "Revised" License
from BlazingOrchard

private static void Add<T>(Node<T> node, ICollection<T> list, IEnumerable<Node<T>> nodes, Func<T, T, bool> hasDependency)
        {
            if (node.Used)
                return;

            node.Used = true;

            foreach (var dependency in nodes.Where(n => hasDependency(node.Item, n.Item)))
            {
                Add(dependency, list, nodes, hasDependency);
            }

            list.Add(node.Item);
        }

19 Source : EnumerableExtensions.cs
with MIT License
from BlazorComponent

public static IList<T> AddIf<T>(this IList<T> items, bool condition, T item)
        {
            items ??= new List<T>();
            if (condition)
            {
                items.Add(item);
            }

            return items;
        }

19 Source : CollectionsExtensions.cs
with MIT License
from BlazorExtensions

public static void Add<T>(this ICollection<T> collection, params T[] args)
        {
            foreach (var item in args)
                collection.Add(item);
        }

19 Source : DataMapper.cs
with GNU General Public License v3.0
from bonarr

internal ICollection<T> Query<T>(string sql, ICollection<T> enreplacedyList, bool useAltName)
        {
            if (enreplacedyList == null)
                throw new ArgumentNullException("enreplacedyList", "ICollection instance cannot be null.");

            if (string.IsNullOrEmpty(sql))
                throw new ArgumentNullException("sql", "A query or stored procedure has not been specified for 'Query'.");

            var mappingHelper = new MappingHelper(this);
            Type enreplacedyType = typeof(T);
            Command.CommandText = sql;
            ColumnMapCollection mappings = MapRepository.Instance.GetColumns(enreplacedyType);

            bool isSimpleType = DataHelper.IsSimpleType(typeof(T));

            try
            {
                OpenConnection();
                using (DbDataReader reader = Command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        if (isSimpleType)
                        {
                            enreplacedyList.Add(mappingHelper.LoadSimpleValueFromFirstColumn<T>(reader));
                        }
                        else
                        {
                            enreplacedyList.Add((T)mappingHelper.CreateAndLoadEnreplacedy<T>(mappings, reader, useAltName));
                        }
                    }
                }
            }
            finally
            {
                CloseConnection();
            }

            return enreplacedyList;
        }

See More Examples