using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace csmic
{
///
/// A generically coded implementation of the ICodedFunction interface.
///
internal class GenericCodedFunction : ICodedFunction
{
#region Members
/// Number of expected arguments.
private int numExpectedArguments;
/// Name of the function.
private string functionName;
/// The method body.
private Func methodBody;
#endregion
#region Constructor
/// Constructor.
/// Name of the function.
/// Number of expected arguments.
/// The method body.
internal GenericCodedFunction(string functionName, int numExpectedArguments, Func methodBody)
{
this.functionName = functionName;
this.numExpectedArguments = numExpectedArguments;
this.methodBody = methodBody;
}
#endregion
#region ICodedFunction Members
/// Gets the number of expected arguments.
/// The total number of expected arguments.
public int NumExpectedArguments
{
get
{
return this.numExpectedArguments;
}
}
/// Gets the name of the function.
/// The name of the function.
public string FunctionName
{
get
{
return this.functionName;
}
}
/// Executes a code block that computes the value of the function.
/// A variable-length parameters list containing arguments.
/// The decimal value computed by the function.
public decimal Execute(params decimal[] args)
{
if (this.methodBody != null)
{
return this.methodBody(args);
}
throw new MissingMethodException(this.GetType().Name, this.functionName);
}
#endregion
}
}