So i was making callbacks, and sometimes i need 2 of them: Before
and After
, so i was trying to wrap them into structure:
public struct DoubleAction<T> where T : System.Delegate
{
public DoubleAction()
{
Before = delegate { };
After = delegate { };
}
public T Before;
public T After;
}
// example usage:
DoubleAction<Action<int, string>> OnWrite;
But Action
, Action<T1>
, etc didn’t have parents, so i can’t limit type T
and create empty delegates automaticly (didn’t want to ?.
each time for Action?
+ its more performance usage when used frequantly)
So i came up with only that solution:
make a lot of DoubleAction types for every Action type:
public struct DoubleAction<T>
{
public DoubleAction()
{
Before = delegate { };
After = delegate { };
}
public Action<T> Before;
public Action<T> After;
}
public struct DoubleAction<T1, T2> { ... }
public struct DoubleAction<T1, T2, T3> { ... }
public struct DoubleAction<T1, T2, T3, T4> { ... }
public struct DoubleAction<T1, T2, T3, T4, T5> { ... }
// and so on
Is there any way to make it more clean?
1