using System; using System.Collections.Generic; using System.Reflection; namespace QFSW.QC { /// /// Wraps a dynamic delegate such as Action and Func so that a lambda can be used as a command. /// public class LambdaCommandData : CommandData { private readonly object _lambdaTarget; /// /// Constructs the command data from the provided lambda. /// /// The lambda to create a command from. To work around type system limitation you may need to first store the lambda in a strong delegate type like Action or Func. /// The name to use for the command. /// The description, if any, for the command. public LambdaCommandData(Delegate lambda, string commandName, string commandDescription = "") : base(lambda.Method, new CommandAttribute(commandName, commandDescription, MonoTargetType.Registry)) { _lambdaTarget = lambda.Target; } protected override IEnumerable GetInvocationTargets(MethodInfo invokingMethod) { yield return _lambdaTarget; } } }