I want to add a lambda function to a Func<T>
. Furthermore I would like the returned value to be that of the first lambda delegate (I cannot initially change the order the first one will always be applied first). When I try to do this with the +=
syntax I get the following:
Error 44 Operator '+=' cannot be applied to operands of type '
System.Func<TEntity>
' and 'lambda expression'
How can I achieve the above? I would really like to avoid using the traditional delegate syntax if possible.
class Transaction
{
static Func<TEntity> ifNullInitializeWithThisReturnedObject = () => default(TEntity);
public static bool IsDirty { get; private set; }
public init (Func<TEntity> IfNullInitializeWithThisReturnedObject)
{
ifNullInitializeWithThisReturnedObject = IfNullInitializeWithThisReturnedObject;
}
public void somemethod()
{
ifNullInitializeWithThisReturnedObject += () =>
{
IsDirty = true;
return default( TEntity );
};
}
}