An open API service indexing awesome lists of open source software.

https://github.com/odonno/extendedcollections

A set of types that extends C# collection types
https://github.com/odonno/extendedcollections

collections csharp dotnet dotnet-standard generics limited-queue queue stack

Last synced: 4 days ago
JSON representation

A set of types that extends C# collection types

Awesome Lists containing this project

README

          

# Extended Collections for .NET

A set of types that extends C# collection types.

### Features

LimitedQueue

A `Queue` with a maximum number of items inside.

```cs
var queue = new LimitedQueue(5); // Max of 5 items in the queue

queue.Enqueue(entity); // Enqueue an item

var result = queue.TryDequeue(); // Try to dequeue an item
if (result.Success)
{
var item = result.Value; // Access dequeued item
}

queue.Enqueued += (sender, e) => {}; // Listen to enqueued items
queue.Dequeued += (sender, e) => {}; // Listen to dequeued items
```

LimitedStack

A `Stack` with a maximum number of items inside.

```cs
var stack = new LimitedStack(5); // Max of 5 items in the stack

stack.Push(entity); // Push an item

var result = stack.TryPop(); // Try to pop an item
if (result.Success)
{
var item = result.Value; // Access popped item
}

stack.Pushed += (sender, e) => {}; // Listen to pushed items
stack.Popped += (sender, e) => {}; // Listen to popped items
```

EntityList

A `List` to store unique items based on a key. A mix between a `List` and a `Dictionary`.

```cs
var list = new EntityList(e => e.Id);

// Upsert a new item
// Add if the key does not exist in the list, update otherwise
list.Upsert(entity);

var entity = list.Find(1); // Find item by key

bool success = list.Remove(1); // Remove using the key

list.Added += (sender, e) => {}; // Listen to added entities
list.Updated += (sender, e) => {}; // Listen to updated entities
list.Removed += (sender, e) => {}; // Listen to removed entities
```