Chr*_*sic 1 c# generics syntax arguments
假设我有两种类似的方法:
public List<object> Do<T>(Stream stream)
{
... does cool things
}
public List<object> Do(Type type, Stream stream)
{
T = type // <- what should this be
return Do<T>(Stream);
}
Run Code Online (Sandbox Code Playgroud)
什么是允许它按预期运行的代码?
我想这个问题必须在这里复制一些东西,但我找不到我的google-fu.
如果你以相反的方式做到这一点很容易:
public List<object> Do<T>(Stream stream)
{
var type = typeof(T);
Do(type, stream);
}
Run Code Online (Sandbox Code Playgroud)
然后另一种方法将包含非重复逻辑.