Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Casting ArrayList entries as different structures (http://www.velocityreviews.com/forums/t114445-casting-arraylist-entries-as-different-structures.html)

=?Utf-8?B?Sm9l?= 11-28-2005 07:11 PM

Casting ArrayList entries as different structures
 
Hello All:

I am writing a function which accepts an ArrayList as its parameter and
converts the contents of the ArrayList into an XmlNodeList. The ArrayList
will contain one of several different structures. For example, the
structures could be either a Customer structure (which contains a customer id
and name) or an Address structure (which contains an address type and street
number, city, etc). The XmlNodeList is uded to populate a DropDownList where
the id or address type are the ListItem's value and other information is the
ListItem's text.

I want the function to determine which structure is in the ArrayList
(Customer or Address) and cast the ArrayList entry appropriately. I can code
everything except the how to determine which structure is in the ArrayList.

For example:

Public Function Foo(AL as ArrayList) as XmlNodeList
Dim e as System.Collections.iEnumerator = AL.GetEnumerator
Do While e.MoveNext
' Determine which structure is contained in e.Current
' Perform other tasks with the e.Current entry of the ArrayList
Loop
'return some XmlNodeList
End Function

Does anyone know how to do this?

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation

cbDevelopment 12-04-2005 01:24 PM

Re: Casting ArrayList entries as different structures
 
You could do something like:

For each O as object in AL
if typeof O is CUSTOMER then ' Process as customer
elseif typeof O is ADDRESS then ' process as address
elseif etc...
end if
Next

Or you could create an interface that all your items share, and you could
cast all the items in the arraylist to that interface and treat them
identically.

----
700cb Development, Inc.
http://www.700cb.net
..NET utilities, developer tools,
and enterprise solutions

=?Utf-8?B?Sm9l?= <joeherro@donotspam.yahoo.com> wrote in
news:C130A837-16FC-4C6F-A6FE-8F719DFA7DDA@microsoft.com:

> Hello All:
>
> I am writing a function which accepts an ArrayList as its parameter
> and converts the contents of the ArrayList into an XmlNodeList. The
> ArrayList will contain one of several different structures. For
> example, the structures could be either a Customer structure (which
> contains a customer id and name) or an Address structure (which
> contains an address type and street number, city, etc). The
> XmlNodeList is uded to populate a DropDownList where the id or address
> type are the ListItem's value and other information is the ListItem's
> text.
>
> I want the function to determine which structure is in the ArrayList
> (Customer or Address) and cast the ArrayList entry appropriately. I
> can code everything except the how to determine which structure is in
> the ArrayList.
>
> For example:
>
> Public Function Foo(AL as ArrayList) as XmlNodeList
> Dim e as System.Collections.iEnumerator = AL.GetEnumerator
> Do While e.MoveNext
> ' Determine which structure is contained in e.Current
> ' Perform other tasks with the e.Current entry of the
> ArrayList
> Loop
> 'return some XmlNodeList
> End Function
>
> Does anyone know how to do this?
>
> TIA,




--


All times are GMT. The time now is 02:42 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.