Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

access parent class?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Justin Rich - 11 Sep 2007 14:24 GMT
i have a class Workstations which inherits collectionbase.
basically Workstations is a collection of Workstation's

my workstations collection has a property called ValidatedCount

the workstation class has a method called Validate()

what i would like to do is use the Workstations class to have a count
(inherited from collectionbase) and have a ValidatedCount...

how do i access the parent class to increase the ValidatedCount property
from the Workstion object in the Workstations class?

Thanks
Justin
Jon Skeet [C# MVP] - 11 Sep 2007 14:48 GMT
> i have a class Workstations which inherits collectionbase.
> basically Workstations is a collection of Workstation's
[quoted text clipped - 8 lines]
> how do i access the parent class to increase the ValidatedCount property
> from the Workstion object in the Workstations class?

There's no natural concept of a "parent" in this case - after all,
unless you've specifically precluded it, a Workstation could be part
of multiple Workstations collections.

Does it take long to validate a Workstation instance? If not, I'd just
make the ValidateCount iterate through all the Workstation instances
in the collection and call Validate on each of them.

Jon
Hans Kesting - 11 Sep 2007 14:49 GMT
> i have a class Workstations which inherits collectionbase. basically
> Workstations is a collection of Workstation's
[quoted text clipped - 11 lines]
> Thanks
> Justin

I don't think you can, as there is no way to identity that "parent".

Some ways around it (that I see):
1. don't remember that "validatedcount" in your collection, but loop through
  all workstations, counting the validated ones.
2. add a "collection" property to your workstation class. When you add a
 workstation to the collection (using an overridden Add method), set that
 property. Then you have a way to notify the collection of validation.
3. Add a "validated" event to the workstation class. When it's validated
 the workstation class raises that event. The collection needs to have
 a handler registered that updates the count.

Can a workstation become "unvalidated" or can it be dropped from the
collection? That should decrease the validated count!

Hans Kestin

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.