added events
This commit is contained in:
@ -4,8 +4,29 @@
|
||||
{
|
||||
private int content;
|
||||
|
||||
public delegate void FullEventHandler(Container container, EventArgs eventArgs);
|
||||
public delegate void OverflowEventHandler(Container container, OverflowEventArgs eventArgs);
|
||||
public event FullEventHandler? Full;
|
||||
public event OverflowEventHandler? Overflowed;
|
||||
|
||||
public int Capacity { get; }
|
||||
public int Content {get => content; set { ArgumentOutOfRangeException.ThrowIfNegative(value, nameof(Content)); ArgumentOutOfRangeException.ThrowIfGreaterThan(value, Capacity, nameof(Content)); content = value; } }
|
||||
public int Content
|
||||
{
|
||||
get => content;
|
||||
set
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(value, nameof(Content));
|
||||
if (value == Capacity)
|
||||
{
|
||||
Full?.Invoke(this, new());
|
||||
}
|
||||
else if (value > Capacity)
|
||||
{
|
||||
Overflowed?.Invoke(this, new(value - Capacity));
|
||||
}
|
||||
content = Math.Min(value, Capacity);
|
||||
}
|
||||
}
|
||||
|
||||
public Container(int capacity, int content)
|
||||
{
|
||||
|
7
Buckets.Logic/OverflowEventArgs.cs
Normal file
7
Buckets.Logic/OverflowEventArgs.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Buckets.Logic
|
||||
{
|
||||
public class OverflowEventArgs(int overflowAmount) : EventArgs
|
||||
{
|
||||
public int OverflowAmount { get; } = overflowAmount;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user