[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mono-devel-list
Subject:    Re: [Mono-dev] inherited event
From:       David Mitchell <dmitchell () logos ! com>
Date:       2009-02-25 19:14:23
Message-ID: C5CAD88F.13A7%dmitchell () logos ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


        The reason that you cannot called inherited events is because the
syntax you use for OnBar is really syntactic sugar for something like this:

protected event OnBar
{
  add { _onBar = Delegate.Combine(_onBar, value); }
  remove { _onBar = Delegate.Remove(_onBar, value); }
}

private EventHandler _onBar;

Once you expand this, itıs easy to see that you canıt call _onBar in child
classes because itıs private. In most cases, this really does make sense,
but if you want different behavior, you can either explicitly define OnBar
in this way and make _onBar protected (or whatever), or you can provide a
protected method (RaiseBar?) that raises the event if OnBar is not null.

--Dave

[Attachment #5 (text/html)]

<HTML>
<HEAD>
<TITLE>RE: inherited event</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'> \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The reason that you cannot called inherited \
events is because the syntax you use for OnBar is really syntactic sugar for \
something like this:<BR> <BR>
protected event OnBar<BR>
{<BR>
&nbsp;&nbsp;add { _onBar = Delegate.Combine(_onBar, value); }<BR>
&nbsp;&nbsp;remove { _onBar = Delegate.Remove(_onBar, value); }<BR>
}<BR>
<BR>
private EventHandler _onBar;<BR>
<BR>
Once you expand this, it&#8217;s easy to see that you can&#8217;t call _onBar in \
child classes because it&#8217;s private. In most cases, this really does make sense, \
but if you want different behavior, you can either explicitly define OnBar in this \
way and make _onBar protected (or whatever), or you can provide a protected method \
(RaiseBar?) that raises the event if OnBar is not null.<BR> <BR>
--Dave</SPAN></FONT>
</BODY>
</HTML>



_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic