I’d like to avoid casting a delegate every time I call MarkAsPermanent method.
Here’s my delegate declaration:
public delegate void Callback<T, U>(T arg1, U arg2);
The method signature I need to call:
class MessengerManager {
static public void MarkAsPermanent(string eventType, Delegate _messageHandler) { ... }
}
The way I call it right now:
MessengerManager.MarkAsPermanent( "level finished", ( Callback<LevelInfo, GameDataType> ) UpdateData );
Is it possible to do something like this instead:
MessengerManager.MarkAsPermanent( "level finished", UpdateData );
I’d like to avoid typing ( Callback<LevelInfo, GameDataType> ) everytime.
One obvious answer: write a helper method:
You can make it generic if you want. Then just call it as:
This is assuming that
MessengerManager‘s declaration really has to use theDelegateparameter – can you just change that method instead?