using System;
using System.Diagnostics;
using System.Collections.Generic;
namespace NLua.Method
{
///
/// We keep track of what delegates we have auto attached to an event - to allow us to cleanly exit a NLua session
///
class EventHandlerContainer : IDisposable
{
private readonly Dictionary _dict = new Dictionary();
public void Add(Delegate handler, RegisterEventHandler eventInfo)
{
_dict.Add(handler, eventInfo);
}
public void Remove(Delegate handler)
{
bool found = _dict.Remove(handler);
Debug.Assert(found);
}
///
/// Remove any still registered handlers
///
public void Dispose()
{
foreach (KeyValuePair pair in _dict)
pair.Value.RemovePending(pair.Key);
_dict.Clear();
}
}
}