473,379 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

CollectionBase Item Member Access

Foundation...Accessing derived class members through a variable of
their base class is just a matter of casting the variable to the
derived class.

How would you access the derived class members in a collection of type
base class where the collection is derived from CollectionBase?

I know that I'm going to feel like a fool when this is resolved, but I
have racked my brain, and almost brought down the Google servers,
single-handedly, searching for the answer.

Thanks in advance...

Nov 17 '05 #1
6 1817
It's not clear what you're trying to do here. Are you trying to access items
that have been added to a collection class derived from CollectionBase? Or
have you added member variables to the derived class that you're trying to
access?

Could you give some more information?

..ARN.

"DelGator" wrote:
Foundation...Accessing derived class members through a variable of
their base class is just a matter of casting the variable to the
derived class.

How would you access the derived class members in a collection of type
base class where the collection is derived from CollectionBase?

I know that I'm going to feel like a fool when this is resolved, but I
have racked my brain, and almost brought down the Google servers,
single-handedly, searching for the answer.

Thanks in advance...

Nov 17 '05 #2
It's not clear what you're trying to do here. Are you trying to access items
that have been added to a collection class derived from CollectionBase? Or
have you added member variables to the derived class that you're trying to
access?

Could you give some more information?

..ARN.

"DelGator" wrote:
Foundation...Accessing derived class members through a variable of
their base class is just a matter of casting the variable to the
derived class.

How would you access the derived class members in a collection of type
base class where the collection is derived from CollectionBase?

I know that I'm going to feel like a fool when this is resolved, but I
have racked my brain, and almost brought down the Google servers,
single-handedly, searching for the answer.

Thanks in advance...

Nov 17 '05 #3
Sorry...

I have a base class, let's call it a "Row", that I have created derived
classes from. So, let's call the derived classes "FileRow" and
"CookieRow". I have also created a "Row" type collection class, based
on CollectionBase.

The derived classes, "FileRow" and "CookieRow" have additional
properties from those inherited from "Row". I want to be able to access
those additional properties from within the collection.

I know how to access the derived class members when dealing with simple
base class variables. You would cast...

(FileRow)Row.derivedClassProperty

What I need is the process for accessing them inside the collection.

Hope this is clearer.

Thanks in advance...

Nov 17 '05 #4
Sorry...

I have a base class, let's call it a "Row", that I have created derived
classes from. So, let's call the derived classes "FileRow" and
"CookieRow". I have also created a "Row" type collection class, based
on CollectionBase.

The derived classes, "FileRow" and "CookieRow" have additional
properties from those inherited from "Row". I want to be able to access
those additional properties from within the collection.

I know how to access the derived class members when dealing with simple
base class variables. You would cast...

(FileRow)Row.derivedClassProperty

What I need is the process for accessing them inside the collection.

Hope this is clearer.

Thanks in advance...

Nov 17 '05 #5
Based on your further explanation, I think that the following may help.

Let's suppose the FileRow class has an integer called fileInt and the
CookieRow class has an int called cookieInt. Suppose the collection class
has a method called DoSomething(). Then you could do something like the
following:

public void DoSomething()
{
foreach( Row r in this )
{
int dRow;
if( r is FileRow )
dRow = ((FileRow)r).fileInt;
else
dRow = ((CookieRow)r).cookieInt;
}
}

The key here is the if( r is FileRow) statement. This identifies r as in
instance of the FileRow class. Then you use the (odd-looking) cast to get to
the FileRow member field.

I hope this helps.

..ARN.
"DelGator" wrote:
Sorry...

I have a base class, let's call it a "Row", that I have created derived
classes from. So, let's call the derived classes "FileRow" and
"CookieRow". I have also created a "Row" type collection class, based
on CollectionBase.

The derived classes, "FileRow" and "CookieRow" have additional
properties from those inherited from "Row". I want to be able to access
those additional properties from within the collection.

I know how to access the derived class members when dealing with simple
base class variables. You would cast...

(FileRow)Row.derivedClassProperty

What I need is the process for accessing them inside the collection.

Hope this is clearer.

Thanks in advance...

Nov 17 '05 #6
Based on your further explanation, I think that the following may help.

Let's suppose the FileRow class has an integer called fileInt and the
CookieRow class has an int called cookieInt. Suppose the collection class
has a method called DoSomething(). Then you could do something like the
following:

public void DoSomething()
{
foreach( Row r in this )
{
int dRow;
if( r is FileRow )
dRow = ((FileRow)r).fileInt;
else
dRow = ((CookieRow)r).cookieInt;
}
}

The key here is the if( r is FileRow) statement. This identifies r as in
instance of the FileRow class. Then you use the (odd-looking) cast to get to
the FileRow member field.

I hope this helps.

..ARN.
"DelGator" wrote:
Sorry...

I have a base class, let's call it a "Row", that I have created derived
classes from. So, let's call the derived classes "FileRow" and
"CookieRow". I have also created a "Row" type collection class, based
on CollectionBase.

The derived classes, "FileRow" and "CookieRow" have additional
properties from those inherited from "Row". I want to be able to access
those additional properties from within the collection.

I know how to access the derived class members when dealing with simple
base class variables. You would cast...

(FileRow)Row.derivedClassProperty

What I need is the process for accessing them inside the collection.

Hope this is clearer.

Thanks in advance...

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: m.pollack | last post by:
Hi all, I have an application which uses a class object that contains a collection. In order to use the PropertyGrid control to expose properties to the user at runtime, I created a...
0
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
1
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
0
by: DelGator | last post by:
Foundation...Accessing derived class members through a variable of their base class is just a matter of casting the variable to the derived class. How would you access the derived class members...
3
by: jason | last post by:
Hello. I've got this simple collection populate code I downloaded from the net (sorry can't find source now) I'm trying to test, but I can't seem to get it to work. Any help would be greatly...
1
by: Matthew Roberts | last post by:
Howdy Everyone, I am having trouble understanding the process of creating a type-safe collection by inheriting from the CollectionBase class. I have done it plenty of times, but now that I sit...
1
by: Kyle Novak | last post by:
I have a question about strongly typed objects when looping through a collection based on the CollectionBase object and using a For..Each loop. I have 2 objects: -Invoice: Holds all properties...
8
by: Yuk Tang | last post by:
I am tearing my hair out over this, since I can't see what I'm doing wrong (duh, if I knew, I wouldn't be asking the question). I am adding Field items to a Field Collection, but for some reason...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.