using System;
using System.Collections.Generic;
namespace SRDebugger
{
///
/// You can implement this interface to create a dynamic "options container".
/// Add the container to SRDebugger via the SRDebug API.
///
///
/// When the container is added via the API, the initial set of options will be fetched via .
/// Options that are added or removed after this point must fire the and events in order
/// for those options to be added/removed from the debug panel.
/// If you do not intend to fire any events (i.e. this is a static container) then should return false.
///
public interface IOptionContainer
{
///
/// Get the initial set of options contained in this object.
///
IEnumerable GetOptions();
///
/// Will the options collection be changed via events?
/// If true, changes to the option set can be provided via the events and .
/// If false, the events will be ignored.
///
bool IsDynamic { get; }
event Action OptionAdded;
event Action OptionRemoved;
}
public sealed class DynamicOptionContainer : IOptionContainer
{
public IList Options
{
get { return _optionsReadOnly; }
}
private readonly List _options = new List();
private readonly IList _optionsReadOnly;
public DynamicOptionContainer()
{
_optionsReadOnly = _options.AsReadOnly();
}
public void AddOption(OptionDefinition option)
{
_options.Add(option);
if (OptionAdded != null)
{
OptionAdded(option);
}
}
public bool RemoveOption(OptionDefinition option)
{
if (_options.Remove(option))
{
if (OptionRemoved != null)
{
OptionRemoved(option);
}
return true;
}
return false;
}
IEnumerable IOptionContainer.GetOptions()
{
return _options;
}
public bool IsDynamic
{
get { return true; }
}
public event Action OptionAdded;
public event Action OptionRemoved;
}
}