I have a delegate that takes quite a few parameters like so:
public delegate void MyDelegate(float thereAre, int lotsOf, string parametersIn, int thisDelegate);
public MyDelegate theDelegateInstance;
This gets quite annoying because Visual Studio 2010 doesn't have any sort of auto complete to help a method match a delegate signature. I basically want to be able to write a method that takes only some of (or none of) the parameters of the delegate and just ignores the others because it doesn't use them anyway.
theDelegateInstance += delegate()
{
Debug.Log("theDelegateInstance was called");
};
Or
theDelegateInstance += delegate(float thereAre, int lotsOf)
{
if(thereAre > lotsOf) Debug.Log("thereAre is way too high");
};
I've found that I can make a method take a delegate return a MyDelegate that calls it like so:
public delegate void VoidMethod();
public static MyDelegate ConvertToMyDelegate(VoidMethod method)
{
return delegate(float thereAre, int lotsOf, string parametersIn, int thisDelegate)
{
method();
};
}
But that requires me to declare a static method for each different conversion.
I just found that I could do my first example without any parameters to achieve the desired result:
theDelegateInstance += delegate//Notice that there are no brackets here.
{
Debug.Log("theDelegateInstance was called");
};
But that only works for inline methods that take no parameters. If I wanted to use even one of the parameters like the second example, I would need to have all of them.