Solved

C# Interface parent class

Posted on 2011-09-29
3
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Data organization issue 7 54
.Net remove carriage returns, line feeds and tabbs 5 32
Read top line from CSV file 14 55
Datagridview column resizing 8 22
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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