none
Hit by CS1911 when trying to use non-generic overload of Observable.FromEvent

    Question

  • Example code:
    public static IObservable<IEvent<MouseEventArgs>> GetMouseDown(this Control control)
    {
        return Observable.FromEvent<MouseEventHandler, MouseEventArgs>(
            h => new MouseEventHandler(h),
            h => control.MouseDown += h,
            h => control.MouseDown -= h
            );
    }
    CS1911: "Access to member 'System.EventHandler<TEventArgs>.Invoke(object, TEventArgs)' through a 'base' keyword from an anonymous method or iterator results in unverifiable code. Consider moving the access into a helper method on the containing type."

    I know this is fixed in the C#4.0 compiler, but I'm playing in 3.5 and VS2008.

    Anyone know if this slipped through the net? Or if I'm doing something wrong? Or if there is a workaround?
    Wednesday, November 18, 2009 11:12 AM

Answers

  • Hi Benjol,

    this will get rid of the warning:

     

    return Observable.FromEvent<MouseEventHandler, MouseEventArgs>(

    h => (o,e)=>h(o,e),

    h => control.MouseDown += h,

    h => control.MouseDown -= h

    );

    Regards,


    Jeffrey

    • Marked as answer by Benjol Thursday, November 19, 2009 6:36 AM
    Wednesday, November 18, 2009 3:58 PM

All replies

  • Hi Benjol,

    this will get rid of the warning:

     

    return Observable.FromEvent<MouseEventHandler, MouseEventArgs>(

    h => (o,e)=>h(o,e),

    h => control.MouseDown += h,

    h => control.MouseDown -= h

    );

    Regards,


    Jeffrey

    • Marked as answer by Benjol Thursday, November 19, 2009 6:36 AM
    Wednesday, November 18, 2009 3:58 PM
  • Thanks,

    and

    ouch! my brain.
    Thursday, November 19, 2009 6:04 AM