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 : ListSnapshot.cs
with MIT License
from 0x0ade

public void Add(T item) {
            ((ICollection<T>) List).Add(item);
        }

19 Source : TransactTracking.cs
with MIT License
from 3F

public TransactTracking<T, TCore> Commit()
        {
            queries.ForEach(s => core.Add(s));
            Reset();
            return this;
        }

19 Source : ExtensionMethods.cs
with MIT License
from Abdesol

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

19 Source : DispatcherObservableCollection.cs
with MIT License
from ABTSoftware

public void Add(T item)
        {
            lock (_syncRoot)
            {
                _collection.Add(item);
                int index = _collection.Count - 1;
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
            }
        }

19 Source : ObservableSortedCollection.cs
with MIT License
from Accelerider

private void CopyFrom(IEnumerable<T> collection)
        {
            if (collection == null) return;

            foreach (T obj in collection)
            {
                Items.Add(obj);
            }
        }

19 Source : CollectionsExtensions.cs
with MIT License
from actions

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

            return collection;
        }

19 Source : ExtendedObservableCollection.cs
with GNU General Public License v3.0
from Acumatica

public void AddRange(IEnumerable<T> range)
		{
			range.ThrowOnNull(nameof(range));
			CheckReentrancy();

			foreach (T item in range)
			{
				Items.Add(item);
			}

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

19 Source : IList.AddIfNotExists.cs
with MIT License
from AdamRamberg

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

            return false;
        }

19 Source : IList.ChainableAdd.cs
with MIT License
from AdamRamberg

public static IList<T> ChainableAdd<T>(IList<T> list, T item)
        {
            list.Add(item);
            return list;
        }

19 Source : IList.GetOrInstantiate.cs
with MIT License
from AdamRamberg

public static T GetOrInstantiate<T>(IList<T> list, UnityEngine.Object prefab, Vector3 position, Quaternion quaternion, Func<T, bool> condition) where T : UnityEngine.Component
        {
            var component = list.First(condition);

            if (component != null)
            {
                component.transform.position = position;
                component.transform.rotation = quaternion;
                return component;
            }

            var newComponent = GameObject.Instantiate(prefab, position, quaternion) as T;
            list.Add(newComponent);
            return newComponent;
        }

19 Source : IList.InstantiateAndAdd.cs
with MIT License
from AdamRamberg

public static T InstantiateAndAdd<T>(IList<T> list, UnityEngine.Object prefab, Vector3 position, Quaternion quaternion) where T : UnityEngine.Component
        {
            var component = GameObject.Instantiate(prefab, position, quaternion) as T;
            list.Add(component);
            return component;
        }

19 Source : Utilities.cs
with MIT License
from ADeltaX

public static C Filter<C, T>(ICollection<T> source, Func<T, bool> predicate) where C : ICollection<T>, new()
        {
            C result = new C();
            foreach (T val in source)
            {
                if (predicate(val))
                {
                    result.Add(val);
                }
            }

            return result;
        }

19 Source : TrackingCollection.cs
with MIT License
from adospace

public void AddRange(IEnumerable<T> items)
        {
            _suspendTracking = true;
            _trackedItems.AddLast(new LinkedListNode<TrackedItem>(TrackedItem.Insert(items.ToArray(), Count)));
            foreach (var item in items)
                Items.Add(item);
            _suspendTracking = false;
        }

19 Source : PostFilterPaginator.cs
with MIT License
from Adoxio

private void Select(int offset, int limit, int itemLimit, ICollection<T> items)
		{
			var selected = _select(offset, limit);

			foreach (var item in selected)
			{
				offset++;

				if (!_filter(item))
				{
					continue;
				}

				items.Add(item);

				if (items.Count >= itemLimit)
				{
					return;
				}
			}

			// If _select returned fewer items than were asked for, there must be no further items
			// to select, and so we should quit after processing the items we did get.
			if (selected.Length < limit)
			{
				return;
			}

			// For the next selection, set the limit to the median value between the original query
			// limit, and the number of remaining items needed.
			var reselectLimit = Convert.ToInt32(Math.Round((limit + (itemLimit - items.Count)) / 2.0, MidpointRounding.AwayFromZero));

			Select(offset, reselectLimit, itemLimit, items);
		}

19 Source : TopPaginator.cs
with MIT License
from Adoxio

private int Gereplacedems(int topLimit, int unfilteredItemOffset, int itemLimit, ICollection<T> items)
		{
			var top = _getTop(topLimit);

			if (unfilteredItemOffset >= top.TotalUnfilteredItems)
			{
				return top.TotalUnfilteredItems;
			}

			foreach (var item in top.Skip(unfilteredItemOffset))
			{
				unfilteredItemOffset++;

				if (!_selector(item))
				{
					continue;
				}

				items.Add(item);

				if (items.Count >= itemLimit)
				{
					return top.TotalUnfilteredItems;
				}
			}

			if (topLimit >= top.TotalUnfilteredItems)
			{
				return items.Count;
			}

			return Gereplacedems(topLimit * _extendedSearchLimitMultiple, unfilteredItemOffset, itemLimit, items);
		}

19 Source : TreeElementUtility.cs
with MIT License
from Adsito

public static void TreeToList<T>(T root, IList<T> result) where T : TreeElement
		{
			if (result == null)
				throw new NullReferenceException("The input 'IList<T> result' list is null");
			result.Clear();

			Stack<T> stack = new Stack<T>();
			stack.Push(root);

			while (stack.Count > 0)
			{
				T current = stack.Pop();
				result.Add(current);

				if (current.children != null && current.children.Count > 0)
				{
					for (int i = current.children.Count - 1; i >= 0; i--)
					{
						stack.Push((T)current.children[i]);
					}
				}
			}
		}

19 Source : TreeModel.cs
with MIT License
from Adsito

public void AddRoot (T root)
		{
			if (root == null)
				throw new ArgumentNullException("root", "root is null");

			if (m_Data == null)
				throw new InvalidOperationException("Internal Error: data list is null");

			if (m_Data.Count != 0)
				throw new InvalidOperationException("AddRoot is only allowed on empty data list");

			root.id = GenerateUniqueID ();
			root.depth = -1;
			m_Data.Add (root);
		}

19 Source : GrpcServerTests.cs
with MIT License
from AElfProject

private IServerStreamWriter<T> MockServerStreamWriter<T>(IList<T> list)
        {
            var mockServerStreamWriter = new Mock<IServerStreamWriter<T>>();
            mockServerStreamWriter.Setup(w => w.WriteAsync(It.IsAny<T>())).Returns<T>(o =>
            {
                list.Add(o);
                return Task.CompletedTask;
            });
            return mockServerStreamWriter.Object;
        }

19 Source : BoundingBoxTree.cs
with The Unlicense
from aeroson

internal override void GetOverlaps(ref BoundingBox boundingBox, IList<T> outputOverlappedElements)
            {
                //Our parent already tested the bounding box.  All that's left is to add myself to the list.
                outputOverlappedElements.Add(element);
            }

19 Source : BoundingBoxTree.cs
with The Unlicense
from aeroson

internal override void GetOverlaps(ref BoundingSphere boundingSphere, IList<T> outputOverlappedElements)
            {
                outputOverlappedElements.Add(element);
            }

19 Source : BoundingBoxTree.cs
with The Unlicense
from aeroson

internal override void GetOverlaps(ref Ray ray, float maximumLength, IList<T> outputOverlappedElements)
            {
                outputOverlappedElements.Add(element);
            }

19 Source : CollectionHelper.cs
with GNU General Public License v3.0
from affederaffe

internal static void AddSorted<T>(this IList<T> list, int index, int count, T value, IComparer<T>? comparer = null)
        {
            comparer ??= Comparer<T>.Default;

            if (list.Count == 0 || comparer.Compare(list[list.Count - 1], value) <= 0)
            {
                list.Add(value);
                return;
            }

            int sortedIndex = list.BinarySearch(index, count, value, comparer);
            list.Insert(sortedIndex, value);
        }

19 Source : TsonDeserializerBase.cs
with Mozilla Public License 2.0
from agebullhu

public void ReadList<T>(IList<T> array, Func<T> read)
        {
            int size = ReadLen();
            for (int idx = 0; idx < size; idx++)
            {
                array.Add(read());
            }
        }

19 Source : CollectionEx.cs
with Mozilla Public License 2.0
from agebullhu

public static void AddOnce<T>(this ICollection<T> list, IEnumerable<T> range)
        {
            if (range == null)
            {
                return;
            }
            foreach (var t in range)
            {
                if (!list.Contains(t))
                    list.Add(t);
            }
        }

19 Source : CollectionEx.cs
with Mozilla Public License 2.0
from agebullhu

public static void AddOnce<T>(this ICollection<T> list, params T[] range)
        {
            if (range == null)
            {
                return;
            }
            foreach (var t in range)
            {
                if (!list.Contains(t))
                    list.Add(t);
            }
        }

19 Source : NotificationList.cs
with Mozilla Public License 2.0
from agebullhu

private void CopyFrom(IEnumerable<T> collection)
        {
            var items = Items;
            if (collection == null || items == null)
                return;
            foreach (var obj in collection)
                items.Add(obj);
        }

19 Source : NotificationList.cs
with Mozilla Public License 2.0
from agebullhu

public void AddRange(IEnumerable<T> collection)
        {
            var items = Items;
            if (collection == null || items == null)
                return;
            foreach (var obj in collection)
                items.Add(obj);
        }

19 Source : EntitySubGridTitle.razor.cs
with Apache License 2.0
from Aguafrommars

protected virtual void OnAddItenClicked()
        {
            var model = CreateModel();
            Collection.Add(model);
            HandleModificationState.EnreplacedyCreated(model);
        }

19 Source : KDTree.cs
with MIT License
from aillieo

public void QueryInRange(Vector2 center, float radius, ICollection<T> toFill)
        {
            if (managed.Count == 0)
            {
                return;
            }

            processingQueue.Clear();
            toFill.Clear();

            float radiusSq = radius * radius;
            
            processingQueue.Enqueue(root);

            while (processingQueue.Count > 0)
            {
                KDNode node = processingQueue.Dequeue();
                if (node.leftLeaf == null && node.rightLeaf == null)
                {
                    // leaf
                    for (int i = node.startIndex; i < node.endIndex; ++i)
                    {
                        int index = permutation[i];
                        if (Vector2.SqrMagnitude(managed[index].position - center) <= radiusSq)
                        {
                            toFill.Add(managed[index]);
                        }
                    }
                }
                else
                {
                    // todo 可以缓存更多信息 加速叶节点的查找
                    if (IsKDNodeInRange(node.leftLeaf, center, radiusSq))
                    {
                        processingQueue.Enqueue(node.leftLeaf);
                    }
                    if (IsKDNodeInRange(node.rightLeaf, center, radiusSq))
                    {
                        processingQueue.Enqueue(node.rightLeaf);
                    }
                }
            }
        }

19 Source : ToObservableTest.cs
with Apache License 2.0
from akarnokd

public void OnNext(T value)
            {
                Values.Add(value);
            }

19 Source : ObservableSourceBuffer.cs
with Apache License 2.0
from akarnokd

public void OnNext(T item)
            {
                if (done)
                {
                    return;
                }

                var buffers = this.buffers;
                try
                {
                    var idx = index;
                    if (idx == 0)
                    {
                        buffers.Enqueue(bufferSupplier());
                    }
                    if (++idx == skip)
                    {
                        index = 0;
                    }
                    else
                    {
                        index = idx;
                    }

                    foreach (var b in buffers)
                    {
                        b.Add(item);
                    }

                    int c = count + 1;

                    if (c == size)
                    {
                        count = size - skip;
                        downstream.OnNext(buffers.Dequeue());
                    }
                    else
                    {
                        count = c;
                    }

                }
                catch (Exception ex)
                {
                    Dispose();
                    OnError(ex);
                }
            }

19 Source : ObservableSourceBuffer.cs
with Apache License 2.0
from akarnokd

public void OnNext(T item)
            {
                if (done)
                {
                    return;
                }

                var b = buffer;
                

                try
                {
                    var idx = index;
                    if (idx == 0)
                    {
                        b = bufferSupplier();
                        buffer = b;
                    }

                    if (b != null)
                    {
                        b.Add(item);

                        var c = count + 1;
                        if (c == size)
                        {
                            count = 0;
                            buffer = default;
                            downstream.OnNext(b);
                        }
                        else
                        {
                            count = c;
                        }
                    }

                    if (++idx == skip)
                    {
                        index = 0;
                    }
                    else
                    {
                        index = idx;
                    }
                }
                catch (Exception ex)
                {
                    Dispose();
                    OnError(ex);
                }
            }

19 Source : ObservableSourceBuffer.cs
with Apache License 2.0
from akarnokd

public void OnNext(T item)
            {
                if (done)
                {
                    return;
                }

                var b = buffer;

                try
                {
                    if (b == null)
                    {
                        b = bufferSupplier();
                        buffer = b;
                    }

                    b.Add(item);
                    var c = count + 1;

                    if (c != size)
                    {
                        count = c;
                        return;
                    }
                    count = 0;
                    buffer = default;
                }
                catch (Exception ex)
                {
                    Dispose();
                    OnError(ex);
                    return;
                }

                downstream.OnNext(b);
            }

19 Source : ObservableSourceBufferBoundary.cs
with Apache License 2.0
from akarnokd

void Drain()
            {
                if (Interlocked.Increment(ref wip) != 1)
                {
                    return;
                }

                var missed = 1;
                var downstream = this.downstream;
                var queue = this.queue;

                for (; ; )
                {
                    if (Volatile.Read(ref disposed))
                    {
                        buffer = default;
                        while (queue.TryDequeue(out var _)) ;
                    }
                    else
                    {
                        var ex = Volatile.Read(ref error);
                        if (ex != null && ex != ExceptionHelper.TERMINATED)
                        {
                            downstream.OnError(ex);
                            Volatile.Write(ref disposed, true);
                            continue;
                        }

                        var success = queue.TryDequeue(out var command);

                        if (success)
                        {
                            if (command.state == StateDone)
                            {
                                var b = buffer;
                                if (hasBuffer)
                                {
                                    downstream.OnNext(b);
                                }
                                downstream.OnCompleted();
                                Volatile.Write(ref disposed, true);
                            }
                            else
                            if (command.state == StateBoundary)
                            {
                                var b = buffer;
                                if (hasBuffer)
                                {
                                    downstream.OnNext(b);
                                }
                                // emit an empty buffer here
                                buffer = default(B);
                                hasBuffer = false;
                            }
                            else
                            {
                                var b = buffer;
                                if (!hasBuffer)
                                {
                                    try
                                    {
                                        b = bufferSupplier();
                                    }
                                    catch (Exception exc)
                                    {
                                        Interlocked.CompareExchange(ref error, exc, null);
                                        continue;
                                    }
                                    hasBuffer = true;
                                    buffer = b;
                                }

                                b.Add(command.item);
                            }
                            continue;
                        }
                    }


                    missed = Interlocked.Add(ref wip, -missed);
                    if (missed == 0)
                    {
                        break;
                    }
                }
            }

19 Source : ReplayAsyncEnumerable.cs
with Apache License 2.0
from akarnokd

public void Next(T item)
            {
                _values.Add(item);
                _size++;
            }

19 Source : FlowableBufferBoundary.cs
with Apache License 2.0
from akarnokd

public void OnNext(T element)
            {
                lock (this)
                {
                    buffer?.Add(element);
                }
            }

19 Source : FlowableBufferSizeExact.cs
with Apache License 2.0
from akarnokd

public void OnNext(T element)
            {
                var b = buffer;
                if (b == null)
                {
                    return;
                }

                b.Add(element);

                var c = count + 1;

                if (c == size)
                {
                    actual.OnNext(b);

                    count = 0;

                    try
                    {
                        buffer = collectionSupplier();
                    }
                    catch (Exception ex)
                    {
                        upstream.Cancel();
                        OnError(ex);
                        return;
                    }
                }
                else
                {
                    count = c;
                }
            }

19 Source : FlowableBufferSizeOverlap.cs
with Apache License 2.0
from akarnokd

void AddTo(T item, C buffer)
            {
                buffer.Add(item);
            }

19 Source : FlowableBufferSizeSkip.cs
with Apache License 2.0
from akarnokd

public void OnNext(T element)
            {
                var b = buffer;
                if (b == null)
                {
                    return;
                }
                int c = count + 1;

                if (c <= size)
                {
                    b.Add(element);
                }
                if (c == size)
                {
                    actual.OnNext(b);

                    try
                    {
                        buffer = collectionSupplier();
                    }
                    catch (Exception ex)
                    {
                        upstream.Cancel();
                        OnError(ex);
                        return;
                    }
                }
                if (c == skip)
                {
                    count = 0;
                } else
                {
                    count = c;
                }
            }

19 Source : DelegateHelper.cs
with Apache License 2.0
from akarnokd

internal static IList<T> Merge(IList<T> first, IList<T> second, IComparer<T> comparer)
        {
            int c1 = first.Count;
            if (c1 == 0)
            {
                return second;
            }
            int c2 = second.Count;
            if (c2 == 0)
            {
                return first;
            }

            IList<T> result = new List<T>(c1 + c2);

            int i = 0;
            int j = 0;

            while (i < c1 && j < c2)
            {
                var v1 = first[i];
                var v2 = second[j];

                int k = comparer.Compare(v1, v2);
                if (k <= 0)
                {
                    result.Add(v1);
                    i++;
                }
                else
                {
                    result.Add(v2);
                    j++;
                }
            }

            while (i < c1)
            {
                result.Add(first[i++]);
            }

            while (j < c2)
            {
                result.Add(second[j++]);
            }

            return result;
        }

19 Source : TestSubscriber.cs
with Apache License 2.0
from akarnokd

public virtual void OnNext(T t)
        {
            CheckSubscribed();
            values.Add(t);
            Volatile.Write(ref valueCount, valueCount + 1);
        }

19 Source : EnumUtils.cs
with MIT License
from akaskela

public static IList<T> GetFlagsValues<T>(T value) where T : struct
        {
            Type enumType = typeof(T);

            if (!enumType.IsDefined(typeof(FlagsAttribute), false))
            {
                throw new ArgumentException("Enum type {0} is not a set of flags.".FormatWith(CultureInfo.InvariantCulture, enumType));
            }

            Type underlyingType = Enum.GetUnderlyingType(value.GetType());

            ulong num = Convert.ToUInt64(value, CultureInfo.InvariantCulture);
            IList<EnumValue<ulong>> enumNameValues = GetNamesAndValues<T>();
            IList<T> selectedFlagsValues = new List<T>();

            foreach (EnumValue<ulong> enumNameValue in enumNameValues)
            {
                if ((num & enumNameValue.Value) == enumNameValue.Value && enumNameValue.Value != 0)
                {
                    selectedFlagsValues.Add((T)Convert.ChangeType(enumNameValue.Value, underlyingType, CultureInfo.CurrentCulture));
                }
            }

            if (selectedFlagsValues.Count == 0 && enumNameValues.SingleOrDefault(v => v.Value == 0) != null)
            {
                selectedFlagsValues.Add(default(T));
            }

            return selectedFlagsValues;
        }

19 Source : CollectionWrapper.cs
with MIT License
from akaskela

public virtual void Add(T item)
        {
            if (_genericCollection != null)
            {
                _genericCollection.Add(item);
            }
            else
            {
                _list.Add(item);
            }
        }

19 Source : CollectionUtils.cs
with MIT License
from akaskela

public static bool AddDistinct<T>(this IList<T> list, T value, IEqualityComparer<T> comparer)
        {
            if (list.ContainsValue(value, comparer))
            {
                return false;
            }

            list.Add(value);
            return true;
        }

19 Source : CollectionUtils.cs
with MIT License
from akaskela

public static void AddRange<T>(this IList<T> initial, IEnumerable<T> collection)
        {
            if (initial == null)
            {
                throw new ArgumentNullException(nameof(initial));
            }

            if (collection == null)
            {
                return;
            }

            foreach (T value in collection)
            {
                initial.Add(value);
            }
        }

19 Source : ReflectionHelper.cs
with MIT License
from AlexGyver

public static void FillList<T>(IEnumerable source, string propertyName, IList<T> list)
        {
            PropertyInfo pi = null;
            Type t = null;
            foreach (var o in source)
            {
                if (pi == null || o.GetType() != t)
                {
                    t = o.GetType();
                    pi = t.GetProperty(propertyName);
                    if (pi == null)
                    {
                        throw new InvalidOperationException(
                            string.Format("Could not find field {0} on type {1}", propertyName, t));
                    }
                }

                var v = pi.GetValue(o, null);
                var value = (T)Convert.ChangeType(v, typeof(T), CultureInfo.InvariantCulture);
                list.Add(value);
            }
        }

19 Source : CollectionExtension.cs
with MIT License
from AlphaYu

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

19 Source : CollectionExtension.cs
with MIT License
from AlphaYu

public static bool AddIf<T>([NotNull] this ICollection<T> @this, Func<T, bool> predicate, T value)
        {
            if (@this.IsReadOnly) return false;
            if (predicate(value))
            {
                @this.Add(value);
                return true;
            }

            return false;
        }

19 Source : CollectionExtension.cs
with MIT License
from AlphaYu

public static bool AddIfNotContains<T>([NotNull] this ICollection<T> @this, T value)
        {
            if (@this.IsReadOnly) return false;
            if ([email protected](value))
            {
                @this.Add(value);
                return true;
            }

            return false;
        }

19 Source : CollectionExtension.cs
with MIT License
from AlphaYu

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

See More Examples