Class CollectionDecoratorExtensions
- Namespace
- Cuemon.Collections.Generic
- Assembly
- Cuemon.Core.dll
Extension methods for the ICollection<T> interface hidden behind the IDecorator<T> interface.
public static class CollectionDecoratorExtensions
- Inheritance
-
CollectionDecoratorExtensions
Examples
CollectionDecoratorExtensions provides extension methods on Decorator.Enclose for bulk-adding elements to ICollection<T> instances using AddRange. This example wraps a List<string> with "apple", "banana" and calls AddRange with individual "cherry", "date", "elderberry" arguments and an array ["fig", "grape"] to insert them in a single operation. Key setup includes calling Decorator.Enclose(list).AddRange(...) to access the non-common extension methods. Console output lists all entries after both bulk insertions, confirming that AddRange accepts both parameterized and array overloads.
using System;
using System.Collections.Generic;
using Cuemon;
using Cuemon.Collections.Generic;
namespace MyApp.Examples
{
public class CollectionDecoratorExtensionsExample
{
public static void Demonstrate()
{
var list = new List<string> { "apple", "banana" };
// Use Decorator to access non-common extension methods
Decorator.Enclose(list).AddRange("cherry", "date", "elderberry");
Decorator.Enclose(list).AddRange(new[] { "fig", "grape" });
Console.WriteLine(string.Join(", ", list));
}}
}
Methods
AddRange<T>(IDecorator<ICollection<T>>, IEnumerable<T>)
Adds the elements of the specified source to the enclosed ICollection<T> of the decorator.
public static void AddRange<T>(this IDecorator<ICollection<T>> decorator, IEnumerable<T> source)
Parameters
decoratorIDecorator<ICollection<T>>The IDecorator{ICollection{T}} to extend.
sourceIEnumerable<T>The sequence of elements that should be added to the enclosed ICollection<T> of the
decorator.
Type Parameters
TThe type of elements in the ICollection<T>.
Exceptions
- ArgumentNullException
decoratorcannot be null.
AddRange<T>(IDecorator<ICollection<T>>, params T[])
Adds the elements of the specified source to the enclosed ICollection<T> of the decorator.
public static void AddRange<T>(this IDecorator<ICollection<T>> decorator, params T[] source)
Parameters
decoratorIDecorator<ICollection<T>>The IDecorator{ICollection{T}} to extend.
sourceT[]The sequence of elements that should be added to the enclosed ICollection<T> of the
decorator.
Type Parameters
TThe type of elements in the ICollection<T>.
Exceptions
- ArgumentNullException
decoratorcannot be null.