Class ActionFactory<TTuple>
- Namespace
- Cuemon
- Assembly
- Cuemon.Core.dll
Provides a way of invoking an Action delegate regardless of the amount of parameters provided.
public sealed class ActionFactory<TTuple> : MutableTupleFactory<TTuple> where TTuple : MutableTuple
Type Parameters
TTupleThe type of the n-tuple representation of a MutableTuple.
- Inheritance
-
MutableTupleFactory<TTuple>ActionFactory<TTuple>
- Inherited Members
Examples
The following example demonstrates how to use to wrap and invoke a delegate with n-tuple arguments.
using System;
using Cuemon;
namespace MyApp.Examples;
public class ActionFactoryExample
{
public void Demonstrate()
{
// Create a mutable tuple with string and int arguments
var tuple = new MutableTuple<string, int>("Hello", 42);
// Define an action that processes the tuple
void Process(MutableTuple<string, int> t)
{
Console.WriteLine($"Message: {t.Arg1}, Value: {t.Arg2}");
// Wrap the action and tuple in an ActionFactory
var factory = new ActionFactory<MutableTuple<string, int>>(Process, tuple);
// Inspect factory state
Console.WriteLine(factory.HasDelegate); // True
Console.WriteLine(factory.GenericArguments.Arg1); // "Hello"
Console.WriteLine(factory.GenericArguments.Arg2); // 42
// Invoke the wrapped delegate
factory.ExecuteMethod(); // Output: "Message: Hello, Value: 42"
// Create a clone for safe concurrent use
var clone = factory.Clone() as ActionFactory<MutableTuple<string, int>>;
clone?.ExecuteMethod();
}}
}
Constructors
ActionFactory(Action<TTuple>, TTuple)
Initializes a new instance of the ActionFactory<TTuple> class.
public ActionFactory(Action<TTuple> method, TTuple tuple)
Parameters
methodAction<TTuple>The delegate to invoke.
tupleTTupleThe n-tuple argument of
method.
ActionFactory(Action<TTuple>, TTuple, Delegate)
Initializes a new instance of the ActionFactory<TTuple> class.
public ActionFactory(Action<TTuple> method, TTuple tuple, Delegate originalDelegate)
Parameters
methodAction<TTuple>The delegate to invoke.
tupleTTupleThe n-tuple argument of
method.originalDelegateDelegateThe original delegate wrapped by
method.
Methods
Clone()
Creates a shallow copy of the current ActionFactory<TTuple> object.
public override MutableTupleFactory<TTuple> Clone()
Returns
- MutableTupleFactory<TTuple>
A new ActionFactory<TTuple> that is a copy of this instance.
Remarks
When thread safety is required this is the method to invoke.
ExecuteMethod()
Executes the delegate associated with this instance.
public void ExecuteMethod()