OnChildChanged... no longer overridable?

OnChildChanged... no longer overridable?

Old forum URL: forums.lhotka.net/forums/t/5514.aspx


ajj3085 posted on Thursday, October 02, 2008

Hi,

Just upgraded to 3.6 beta 1, and am getting a compile error that OnChildChanged is not overridable, because it's not marked virtual.

Was this intentional?  How do we handle this... it would be odd to listen for an event from my own instance.

Thanks
Andy

ajj3085 replied on Thursday, October 02, 2008

Ok... the signature changed... but I still have a question..

Do we override OnChildChanged, or OnChildChangedInternal?  Also, should OnChildChangedInternal be OnChildChangedCore, to be consistent with other parts of .Net (AddNew, AddNewCore, etc.).

RockfordLhotka replied on Thursday, October 02, 2008

I think it depends on what you are trying to do.

The trick with the ChildChanged event is that it cascades up the chain, but also that it originates in response to PropertyChanged or ListChanged. Without care, you could end up with too many events being raised.

If all you want is to be notified that a child changed, the OnChildChanged() is the thing to override.

If you want to muck around with the plumbing and change the way the event cascades, then OnChildChangedInternal() is the thing to override.

I don't think "Core" and "Internal" are comparable here. In this case "Internal" means that these methods are part of the internal plumbing infrastructure that cascades the event up the parent-child chain.

ajj3085 replied on Friday, October 03, 2008

Well, in my case I'm trying to run a rule over a collection to ensure that a part number exists once in the list.  So in my root (which contains the BLB) I override OnChildChanged, and if the source is the collection, I call a CheckRules on the collection, which asks each object to check itself.

Also, it does seem like I want OnChildChanged, not the internal version.  Thanks for clearing that up.

tchimev replied on Friday, January 23, 2009

I have the same situation.
A root object with child BLB.
I try to recheck the rules of each object in the collection after child BLB changed.

How do you call CheckRules on the child collection to ask each object to check itself?
Did you implement it yourself?

Thank you.

ajj3085 replied on Friday, January 23, 2009

The BLB has a method, internal void CheckRules(), that iterates each item in the collection.  It in turn calls an internal void CheckRules method which exists on the BB child type; that method simply calls ValidationRules.CheckRules();

tchimev replied on Saturday, January 24, 2009

Thank you very much, I'll try it.

Copyright (c) Marimer LLC