Solved

C# Interface parent class

Posted on 2011-09-29
3
231 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

14 Experts available now in Live!

Get 1:1 Help Now