Какую версию выбрать?
Как я и сказал :)
-----
Увы...
Но меня не интересует написание и использование методов под каждый тип - меня интересует проперть-с-ограничением по типам...
public class Type1 { }
public class Type2 { }
public class Type3 { }
public class WorkingCode
{
WorkingCode() {
TypedPropertyHolder tph = null;
tph.Value = new Type1(); // Ok
tph.Value = new Type2(); // Ok
tph.Value = new Type3(); // Error at compilation time
}
}
public class TypedPropertyHolder
{
internal TypeProxy Value { get; set; } // define restriction to use Type1 and Type2 only
}
internal class TypeProxy
{
object t;
internal TypeProxy(object pT) { t = pT; }
public static implicit operator TypeProxy(Type1 t1) { return new TypeProxy(t1); }
public static implicit operator TypeProxy(Type2 t2) { return new TypeProxy(t2); }
public static implicit operator Type1(TypeProxy p) { return (Type1)p.t; }
public static implicit operator Type2(TypeProxy p) { return (Type2)p.t; }
}
Вроде вспомнил как делал...