Hello everyone.
So… I am getting an error message, in a quite specific situation…
I have this event:
public event Action<AnimationCurve, AnimationCurve, AnimationCurve, AnimationCurve> onDoSomething;
And this is actually ok… it compiles and works as intended…
However, when I add another AnimationCurve as parameter, like in:
public event Action<AnimationCurve, AnimationCurve, AnimationCurve, AnimationCurve, AnimationCurve> onDoSomething;
I get the error message:
error CS0308: The non-generic type `System.Action’ cannot be used with the type arguments
I believe anyone can try it out and see it…
My question is: is this a know issue? Has anyone ever had this kind of trouble?
I intend to get everything on a list, and send it as a generic list. But that is kind of a surprise for me…
Any thoughts?
You can’t use more than 4 parameters in the built-in Action delegate. That’s the limitation of .NET framework 3.5.
You can always create any number of custom delegates, for example:
public delegate void DoSomethingHandler(AnimationCurve a1, AnimationCurve a2, AnimationCurve a3, AnimationCurve a4, AnimationCurve a5);
public event DoSomethingHandler OnDoSomething;
If you prefer generic approach:
public delegate void Action<T1, T2, T3, T4, T5>(T1 arg, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
Why dont you create a Value Object class for your multiple parameters and then only pass the VO ?
That is a good idea. Or better, if you have an arbitrary number of curves, you could go with params:
public delegate void CurveHandler(params AnimationCurve[] curves);
So you can:
public CurveHandler OnDoSomething = delegate(AnimationCurve[] curves)
{
foreach (AnimationCurve curve in curves)
{
// do something with a curve
}
};
Unfortunately, I am not familiar with the creation of “Value Objects”…
Can you instruct me on that, please?
*btw, the generic list worked fine