Assume this type:
public class Car { }
And I create an instance of that:
Car myCar = new Car();
Target target = new Target();
target.Model = myCar;
And this is another Type:
public class Target {
public object Model { get; set; }
string GetName(){
//Use Model and return myCar in this Example
}
}
As I showed in code the GetName
method must use an object type (Model
) and returned the name of instance that is myCar in this example? what is your suggestion is there any way to do this?
Update How about this:
public class Car {
public string Title { get; set; }
}
And I pass to target: target.Model = Car.Title
And GetName()
method returned Title
?
Model
just an object instead of aCar
(or a subclass of it)? – Tim Schmelter Apr 18 '12 at 8:17Target
is. But you'd want to dotarget.Model = myCar
and then probably later cast it back to aCar
and access theTitle
property. So something likeCar car = target.Model as Car; if (car != null) { // Do something with your car object }
. – Adrian Thompson Phillips Apr 18 '12 at 8:43