Solved

C# Interface parent class

Posted on 2011-09-29
3
230 Views
Last Modified: 2013-12-17
I have a single object which can be derived from 3 separate classes.  This derived object is then passed as a parameter into another class method.  How do I determine which parent class owned my parameter?  

Please refer to the code below:

DriverFord myFord = new DriverFord();
DriverChevy myChevy = new DriverChevy();
DriverHonda myHonda = new DriverHonda();
CarWheel myWheel = new CarWheel();

myWheel = myFord.GetWheel;   //I created a Ford wheel object

SomeClass.SomeMethod(myWheel);  //How do I determine whether that wheel came from a Ford, Chevy, or Honda object?

Open in new window

0
Comment
Question by:Phil5780
3 Comments
 
LVL 4

Accepted Solution

by:
theHollow earned 500 total points
ID: 36818360
Hi
You cannot fint that from the "myWheel" variable alone. Not unless you put something in that class which says something about the parent.
You need to get the type (.GetType() method) from the owning class (DriverFord, DriverChevy or DriverHonda).
0
 
LVL 15

Expert Comment

by:Eyal
ID: 36818374
Type parameterType = oHandlerResponse.Data.GetType();
0
 

Author Closing Comment

by:Phil5780
ID: 36818433
Got it!  By using the Type.Name I was able to nail down who the parent is.  Thanks!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now