public abstract class Vehicle
{
protected void SomeMethod<T>(String paramName, ref T myParam, T val)
{
//Get the Type that myParam belongs to...
//(Which happens to be Car or Plane in this instance)
Type t = typeof(...);
}
}
public class Car : Vehicle
{
private String _model;
public String Model
{
get { return _model; }
set { SomeMethod<String>("Model", ref _model, value); }
}
}
public class Plane: Vehicle
{
private Int32 _engines;
public In32 Engines
{
get { return _engines; }
set { SomeMethod<Int32>("Engines", ref _engines, value); }
}
}
难道我能做些什么? 即,利用参考参数我的帕拉姆某种方式,获得某种类型(碳)或类型(Plane)?
奥赫,我想避免在这样的情况下通过一些Method,或者如果我能够的话增加另一个通用的限制参数。