// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) 2014 OxyPlot contributors
//
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using System.Reflection;
using OxyPlot;
///
/// Provides information about an example.
///
public class ExampleInfo
{
///
/// The method to invoke.
///
private readonly MethodInfo method;
///
/// The result of the method call.
///
private object result;
///
/// Initializes a new instance of the class.
///
/// The category.
/// The title.
/// The tags.
/// The method.
public ExampleInfo(string category, string title, string[] tags, MethodInfo method)
{
this.Category = category;
this.Title = title;
this.Tags = tags;
this.method = method;
}
///
/// Gets the category.
///
///
/// The category.
///
public string Category { get; private set; }
///
/// Gets the title.
///
///
/// The title.
///
public string Title { get; private set; }
///
/// Gets the tags.
///
///
/// The tags.
///
public string[] Tags { get; private set; }
///
/// Gets the plot model.
///
///
/// The plot model.
///
public PlotModel PlotModel
{
get
{
var plotModel = this.Result as PlotModel;
if (plotModel != null)
{
return plotModel;
}
var example = this.Result as Example;
return example != null ? example.Model : null;
}
}
///
/// Gets the plot controller.
///
///
/// The plot controller.
///
public IPlotController PlotController
{
get
{
var example = this.Result as Example;
return example != null ? example.Controller : null;
}
}
///
/// Gets the code.
///
///
/// The code.
///
public string Code
{
get
{
return this.PlotModel != null ? this.PlotModel.ToCode() : null;
}
}
///
/// Gets the result.
///
///
/// The result.
///
private object Result
{
get
{
return this.result ?? (this.result = this.method.Invoke(null, null));
}
}
///
/// Returns a that represents this instance.
///
///
/// A that represents this instance.
///
public override string ToString()
{
return this.Title;
}
}
}