Casting an Object to its own type 
Author Message
 Casting an Object to its own type

Dim d as clsItemBase = new clsDealer()
Dim m as clsItemBase = new clsMaster()
   ' ItemBase is the base type of Dealer and Master

Because the ID fields are different formats (legacy code)
I would like to do something like this.

debug.writeline(CType(d, d.gettype).ID.ToString())
debug.writeline(CType(m, m.gettype).ID.ToString())

I need to cast each item to its own type so that it will
use its own ID property.  How?



Wed, 21 Sep 2005 03:40:57 GMT  
 Casting an Object to its own type


Quote:
> Dim d as clsItemBase = new clsDealer()
> Dim m as clsItemBase = new clsMaster()
>    ' ItemBase is the base type of Dealer and Master

> Because the ID fields are different formats (legacy code)
> I would like to do something like this.

> debug.writeline(CType(d, d.gettype).ID.ToString())
> debug.writeline(CType(m, m.gettype).ID.ToString())

> I need to cast each item to its own type so that it will
> use its own ID property.  How?

Is ID a property of the base class (ItemBase)?  Why can't you just use:

debug.writeline(d.ID.ToString())
debug.writeline(m.ID.ToString())

Chris

--
If you don't like lunchmeat, please remove it from my e-mail address to
send me an e-mail



Wed, 21 Sep 2005 03:53:06 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Casting an object to its own type at runtime

2. Type Casting Objects in VB

3. Typecasting an object to its own type at runtime

4. Question about type casting in .Net

5. Casting an array's type?

6. Cast from String to type Double is not valid

7. How to cast to interface type?

8. Help - Enumerated types and casting

9. Type casting

10. Type Casting Nightmare

11. Type Cast

12. Casting/cooercing variable types?

 

 
Powered by phpBB® Forum Software