假设下面的界面,我使用来定义参数类型和用于存储过程返回类型...使用通用接口作为typeparameter为方法或函数
public interface IStoredProcedure<out TReturn, out TParameter>
where TReturn : class
where TParameter : class
{
TReturn ReturnType { get; }
TParameter ParameterType { get; }
}
...是有可能通过这个界面作为TypeParameter
的一种方法?沿此线的东西(不编译)
public static void DoAction<TProcedure>(TProcedure procedure1)
where TProcedure : IStoredProcedure<TReturnType, TParameterType>
{
// do some work
}
...或沿着这些路线的东西...
public static void DoAction<IStoredProcedure<TReturnType, TParameterType>>(IStoredProcedure procedure1)
where TReturnType : class
where TParameterType : class
{
// do some work
}
没有这两种方法的编译,我只是不能工作了如何编写它们以使其编译。在DoAction()
方法中,我需要intergate参数的类型和返回类型。
我不确定这个编译。它不应该是'DoAction'? –
@Charles:对不起,是的。重点是参数,并没有发现类型参数问题。固定。 –
是的,现在的作品谢谢你,并回答alsow什么是我的下一个问题是如何使该方法成为一个函数返回一个TReturnType的列表,但现在所有的作品现在这样.. public list的getAction (IStoredProcedure 程序1) 其中TReturnType:类 其中TParameterType:类 {// 做一些工作 返回新的List (); } –
Dib