views:

191

answers:

2

Hi, I'm restructuring opur code to use generics. We do use (out of necessity, no changes possible here) own code to attach/detach/iterate/calls delegates. Before there were classes X, Y, Z which declared their own:

public delegate void Event_x_Delegate(ref ComParam pVal, out bool result);

At the moment I'm passing this delegate to the generic class:

public sealed class Event_X_Handling  : BasicEvent<Event_X_Handling.Event_x_Delegate>

with the BasicEvent beeing

public abstract class BasicEvent<DELEGATE> : Loggable
    where DELEGATE: class { ...

This works just fine, so I had the attach/detach-functionality generalized.

But now I'd like to generalize the iteration/calling too. As X,Y,Z only differ in the "ref ComParam pVal" something like this works nice:

public abstract class BasicEventListener<EVENTPARAM1> :
    BasicEvent<BasicEventListener<EVENTPARAM1>.BasicDelegate<EVENTPARAM1>> {

    #region TYPES

    public delegate void BasicDelegate<PARAM1>(ref EVENTPARAM1 pVal, out bool result);

    #endregion

with X,Y,Z changing to:

public sealed class Event_X_Handling  : BasicEventListener<ComParam>

But here comes the problem lurking around the corner: attach/detach now work with a BasicEventListener.BasicDelegate. But a lot of code. refers to Event_X_Handling.Event_x_Delegate, as they unfortunately used the NET1.1-syntax for creating delegates (beeing a typed Event += new Delegate_X(_listen)).

So in short: is there a way to alias an Event_x_Delegate to a BasicDelegate? I can't really see any other possibilities.

PS: Of course I see that with breaking the base classes down to dynamic invocation in the iterating/calling I could implement it without introducing the BasicDelegate. But this is not very elegant IMHO.

+1  A: 

No, there's no equivalent of typedef (which I think is what you're asking for).

I have to say, search-and-replace may be your friend here!

Daniel Earwicker
+1  A: 

Perahps a using alias will work for you?

using System;

using IntFunc = System.Func<int>;

namespace DelegateAlias
{
    class Program
    {
     static int foo() { return 314; }
     static void Main(string[] args)
     {
  IntFunc f = foo;
     }
    }
}
Dan