using System;
using SRF.Helpers;
namespace SRDebugger
{
///
/// Class describing how an option should be presented within the options panel.
///
public sealed class OptionDefinition
{
///
/// Display-name for the option.
///
public string Name { get; private set; }
///
/// The category that this option should be placed within.
///
public string Category { get; private set; }
///
/// Sort order within the category. Order is low to high, (options with lower SortPriority will appear before
/// options with higher SortPriority).
///
public int SortPriority { get; private set; }
///
/// Whether this option is a method that should be invoked.
///
public bool IsMethod
{
get { return Method != null; }
}
///
/// Whether this option is a property that has a value.
///
public bool IsProperty
{
get { return Property != null; }
}
///
/// The underlying method for this OptionDefinition.
/// Can be null if is false.
///
public SRF.Helpers.MethodReference Method { get; private set; }
///
/// The underlying property for this OptionDefinition.
/// Can be null if is false.
///
public SRF.Helpers.PropertyReference Property { get; private set; }
private OptionDefinition(string name, string category, int sortPriority)
{
Name = name;
Category = category;
SortPriority = sortPriority;
}
public OptionDefinition(string name, string category, int sortPriority, SRF.Helpers.MethodReference method)
: this(name, category, sortPriority)
{
Method = method;
}
public OptionDefinition(string name, string category, int sortPriority, SRF.Helpers.PropertyReference property)
: this(name, category, sortPriority)
{
Property = property;
}
public static OptionDefinition FromMethod(string name, Action callback, string category = "Default", int sortPriority = 0)
{
return new OptionDefinition(name, category, sortPriority, callback);;
}
///
/// Create an option definition from a setter and getter lambda.
///
/// Name to display in options menu.
/// Method to get the current value of the property.
/// Method to set the value of the property (can be null if read-only)
/// Category to display the option in.
/// Sort priority to arrange the option within the category.
/// The created option definition.
public static OptionDefinition Create(string name, Func getter, Action setter = null, string category = "Default", int sortPriority = 0)
{
return new OptionDefinition(name, category, sortPriority, PropertyReference.FromLambda(getter, setter));
}
}
}