[CSHARP-3242] Fix eventing code examples Created: 28/Oct/20  Updated: 21/Nov/22

Status: Backlog
Project: C# Driver
Component/s: Documentation
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Dmitry Lukyanov (Inactive) Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

This code example is invalid and won't be compiled https://mongodb.github.io/mongo-csharp-driver/2.10/reference/driver_core/events/.

public class MyEventSubscriber : IEventSubscriber
{
    public bool TryGetEventHandler<TEvent>(out Action<TEvent> handler)
    {
        if(typeof(TEvent)) == typeof(ConnectionPoolAddedConnectionEvent))
        {
            handler = (Action<TEvent>)HandleConnectionPoolAddedConnectionEvent;
            return true;
        }
        handler = null;
        return false;
    }
    private void HandleConnectionPoolAddedConnectionEvent(ConnectionPoolAddedConnectionEvent @event)
    {
        Console.WriteLine("Added a connection to the pool.");
    }
}

It should be fixed.

Also, Handle methods should be public


Generated at Wed Feb 07 21:44:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.