Note that there are some explanatory texts on larger screens.

plurals
  1. POInheritance & Events
    text
    copied!<p>I have an interface defined like so:</p> <pre><code>public interface IRipper { IRipperHost Host { get; set; } void Rip(FileStream stream); event RipperEventHandler OnStart; event RipperEventHandler OnComplete; event RipperEventHandler OnProgressChanged; } public delegate void RipperEventHandler(object sender, RipperEventArgs e); </code></pre> <p>and a base class that implements that interface</p> <pre><code>public class RipperBase : IRipper { public void Rip(FileStream stream) { throw new System.NotImplementedException(); } public event RipperEventHandler PostRipEvent; event RipperEventHandler IRipper.OnComplete { add { if (PostRipEvent != null) { lock (PostRipEvent) { PostRipEvent += value; } } else { PostRipEvent = value; } } remove { if (PostRipEvent != null) { lock (PostRipEvent) { PostRipEvent -= value; } } } } ... and so on } </code></pre> <p>My question is how would <strong><em>you</em></strong> inherit from RipperBase and override the BaseClass Rip method. in reality that function should be abstract - but i don't know how to do that with interfaces. </p> <p>Also how can i call the base classes event handler from the class derived from RipperBase? I tried this</p> <pre><code> RipperEventHandler handler = PreRipEvent; if (handler != null) { handler(this, new RipperEventArgs { Message = "Started Ripping file to CSV!" }); } handler = RipProgEvent; </code></pre> <p>this but I'm getting the "event can only appear on the left hand side of += or -=." error</p> <p>any help would be greatly appreciated! I'm trying to make this as scalable as possible. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload