Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# Interface parent class

Posted on 2011-09-29
3
Medium Priority
?
241 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

885 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