代码之家  ›  专栏  ›  技术社区  ›  Leonidas

是否可以从代理中别名/引用代理?

  •  1
  • Leonidas  · 技术社区  · 17 年前

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

    public sealed class Event_X_Handling  : BasicEvent<Event_X_Handling.Event_x_Delegate>
    

    带着最基本的东西

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

    这工作得很好,所以我将附加/分离功能进行了推广。

    但是现在我也要概括一下迭代/调用。由于X、Y、Z仅在“ref ComParam pVal”中有所不同,类似这样的方法很好:

    public abstract class BasicEventListener<EVENTPARAM1> :
        BasicEvent<BasicEventListener<EVENTPARAM1>.BasicDelegate<EVENTPARAM1>> {
    
        #region TYPES
    
        public delegate void BasicDelegate<PARAM1>(ref EVENTPARAM1 pVal, out bool result);
    
        #endregion
    

    X、Y、Z更改为:

    public sealed class Event_X_Handling  : BasicEventListener<ComParam>
    

    但问题就在这里:现在使用一个 BasicEventListener.BasicDeleteGate . 但是有很多代码。指 事件处理。事件处理委托 ,因为他们不幸地使用了NET1.1语法来创建委托(使用键入的 事件+=新委托\u X(\u侦听)

    简言之,有没有办法给一个 事件x代表 到 基本要素 ? 我真的看不到任何其他的可能性。

    PS:当然,我看到通过在迭代/调用中将基类分解为动态调用,我可以在不引入 基本要素 . 但这不是很优雅。

    2 回复  |  直到 17 年前
        1
  •  12
  •   Ðаn    6 年前

    Perahps a using alias对你有用吗?

    using System;
    
    using IntFunc = System.Func<int>;
    
    namespace DelegateAlias
    {
        class Program
        {
            static int foo() { return 314; }
            static void Main(string[] args)
            {
               IntFunc f = foo;
            }
        }
    }
    
        2
  •  1
  •   Daniel Earwicker    17 年前

    typedef (我想这就是你想要的)。

    我不得不说,搜索和替换可能是你在这里的朋友!