using System;
using System.Collections.Generic;
using SRDebugger.Internal;
namespace SRDebugger
{
public delegate void OptionValueChangedHandler(OptionDefinition option);
///
/// You can implement this interface to create a dynamic "options container".
/// Add the container to SRDebugger via the SRDebug API.
///
public interface IOptionContainer
{
///
/// Get the initial set of options contained in this object.
///
IEnumerable GetOptions();
///
/// Will the options collection be changed?
/// If true, the current set of options will be retrieved via and subsequent changes
/// will need to be provided via and .
///
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;
}
}