T
C#では、タイプを証明できるタイプにキャストできませんT
。どうすればT
そのタイプにキャストできますか?
public static T _cast<T> (object o) {
if (typeof(T) == typeof(string)) {
return (T) o.ToString(); // Compiler YELLS!
}
throw new InvalidCastException("missing compiler generated case");
}
私はC++からC#にコードを生成するプログラムを書いています。この_cast
操作は、C++の代わりに使用したいと思いますoperator T ()
。