InteractiveScapeGmbH / TuioNet

MIT License
7 stars 1 forks source link

Suggestion: Use .NET Event Pattern #13

Closed eqbic closed 4 months ago

eqbic commented 9 months ago

Problem

Right now we use C# Actions for events to propagate changes like so:

/// <summary>
/// Event gets triggered when a new TUIO 1.1 cursor is recognized.
/// </summary>
public event Action<Tuio11Cursor> OnCursorAdded;
...
OnCursorAdded?.Invoke(cursor);

To increase compatibility and fullfill expectations of other .Net developers I suggest to use the Event Pattern.

Suggestion

/// <summary>
/// Event gets triggered when a new TUIO 1.1 cursor is recognized.
/// </summary>
public event EventHandler<Tuio11Cursor> OnCursorAdded;
...
OnCursorAdded?.Invoke(this, cursor);

This would lead to breaking changes since the listener to the event would need to change the method signature from:

processor.OnCursorAdded += CursorAdded;
private static void CursorAdded(Tuio11Cursor cursor)
{
    Console.WriteLine($"New cursor added -> ID: {cursor.CursorId}");
}

To:

processor.OnCursorAdded += CursorAdded;
private static void CursorAdded(object sender, Tuio11Cursor cursor)
{
    Console.WriteLine($"New cursor added -> ID: {cursor.CursorId}");
}

Thoughts

I am aware that breaking changes in the public API are an issue. But having a standardized way of using events should be worth the possible trouble.