Class FuncFactory<TTuple, TResult>
- Namespace
- Cuemon
- Assembly
- Cuemon.Core.dll
Provides a way of invoking an Func<TResult> delegate regardless of the amount of parameters provided.
public sealed class FuncFactory<TTuple, TResult> : MutableTupleFactory<TTuple> where TTuple : MutableTuple
Type Parameters
TTupleThe type of the n-tuple representation of a MutableTuple.
TResultThe type of the return value of the function delegate Cuemon.FuncFactory<TTuple, TResult>.Method.
- Inheritance
-
MutableTupleFactory<TTuple>FuncFactory<TTuple, TResult>
- Inherited Members
Examples
The following example demonstrates how to use FuncFactory<TTuple, TResult> to encapsulate a function delegate and its arguments together for deferred execution.
using System;
using Cuemon;
namespace Contoso.Formatting;
public sealed class FuncFactoryExample
{
public static void Run()
{
var factory = new FuncFactory<MutableTuple<string, int>, string>(
tuple => $"{tuple.Arg1}-{tuple.Arg2:D3}",
new MutableTuple<string, int>("Item", 7));
string result = factory.ExecuteMethod();
var clone = (FuncFactory<MutableTuple<string, int>, string>)factory.Clone();
Console.WriteLine(result);
Console.WriteLine(clone.ExecuteMethod());
}
}
Constructors
FuncFactory(Func<TTuple, TResult>, TTuple)
Initializes a new instance of the FuncFactory<TTuple, TResult> class.
public FuncFactory(Func<TTuple, TResult> method, TTuple tuple)
Parameters
methodFunc<TTuple, TResult>The function delegate to invoke.
tupleTTupleThe n-tuple argument of
method.
FuncFactory(Func<TTuple, TResult>, TTuple, Delegate)
Initializes a new instance of the FuncFactory<TTuple, TResult> class.
public FuncFactory(Func<TTuple, TResult> method, TTuple tuple, Delegate originalDelegate)
Parameters
methodFunc<TTuple, TResult>The function delegate to invoke.
tupleTTupleThe n-tuple argument of
method.originalDelegateDelegateThe original delegate wrapped by
method.
Methods
Clone()
Creates a shallow copy of the current FuncFactory<TTuple, TResult> object.
public override MutableTupleFactory<TTuple> Clone()
Returns
- MutableTupleFactory<TTuple>
A new FuncFactory<TTuple, TResult> that is a copy of this instance.
Remarks
When thread safety is required this is the method to invoke.
ExecuteMethod()
Executes the function delegate associated with this instance.
public TResult ExecuteMethod()
Returns
- TResult
The result of the function delegate associated with this instance.