首页 新闻 会员 周边

Delegate和MulticastDelegate都是抽象方法,为什么可以实例化呢?

0
悬赏园豆:20 [已解决问题] 解决于 2012-03-24 16:39

MulticastDelegate定义:

[Serializable]
public abstract class MulticastDelegate : Delegate
{
    // Fields
    private MulticastDelegate _prev;

    // Methods
    protected MulticastDelegate(object target, string method) : base(target, method)
    {
    }

    protected MulticastDelegate(Type target, string method) : base(target, method)
    {
    }

。。。

Delegate的定义;

Serializable, ClassInterface(ClassInterfaceType.AutoDual)]
public abstract class Delegate : ICloneable, ISerializable
{
    // Fields
    private RuntimeMethodInfo _method;
    private IntPtr _methodPtr;
    private IntPtr _methodPtrAux;
    private object _target;

    // Methods
    private Delegate()
    {
        this._method = null;
        this._methodPtrAux = IntPtr.Zero;
    }

    protected Delegate(object target, string method)
    {
        this._method = null;
        this._methodPtrAux = IntPtr.Zero;
        if (target == null)
        {
            throw new ArgumentNullException("target");
        }
        if (method == null)
        {
            throw new ArgumentNullException("method");
        }
        this.InternalCreate(target, method, false);
    }

    protected Delegate(Type target, string method)
    {
        this._method = null;
        this._methodPtrAux = IntPtr.Zero;
        if (target == null)
        {
            throw new ArgumentNullException("target");
        }
        if (!(target is RuntimeType))
        {
            throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "target");
        }
        if (method == null)
        {
            throw new ArgumentNullException("method");
        }
        this.InternalCreateStatic((RuntimeType) target, method);
    }

 

 。。。

但是:

public delegate void Feedback(System.Object value);

private void FeedbackToConsole(System.Object value)

{

  Console.WriteLine("Processing {0}",value);

}

调用:

Set.ProcessingItem(

  new Set.Feedback((new Program()).FeedbackToConsole)

);

问题是:Delegate和MulticastDelegate都没有单个参数的构造函数(单个参数会出异常),却可以正常执行,搞不懂啊?

szjdw的主页 szjdw | 初学一级 | 园豆:6
提问于:2012-03-24 16:23
< >
分享
最佳答案
0

  .method public hidebysig specialname rtspecialname instance void .ctor(object 'object', native int 'method')runtimemanaged { }

 

运行时托管的,自动产生两个参数:object和method

szjdw | 初学一级 |园豆:6 | 2012-03-24 16:36
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册