【发布时间】:2011-10-14 21:47:58
【问题描述】:
我有一堂课:
class abc <T> {
private T foo;
public string a {
set {
foo = T.parse(value);
}
get{
return foo.toString();
}
}
}
但是 T.parse 命令给了我一个错误。有人可以做我想做的事吗?
我将它用作其他一些派生类的基类。
编辑:
我结束了我们的工作:
Delegate parse = Delegate.CreateDelegate(typeof(Func<String, T>), typeof(T).GetMethod("Parse", new[] { typeof(string) }));
我在构造函数中做了一次
然后我在我的财产中执行以下操作:
lock (lockVariable)
{
m_result = (T)parse.DynamicInvoke(value);
dirty = true;
}
【问题讨论】:
-
这个编译? parse 方法从何而来?
-
@fantasticfix Sam 想要使用类的 Parse 功能,例如 Int32.Parse 或 Boolean.Parse。
标签: c#