简体   繁体   English

有没有一种方法可以将类型参数约束为SqlDbType?

[英]Is there a way to constrain a type parameter to SqlDbType?

I'm looking to constrain a type parameter to SqlDbType for a generic factory method. 我正在寻找将类型参数限制为SqlDbType的通用工厂方法。 Here's my attempt at the signature: 这是我对签名的尝试:

    private static SqlParameter SqlParameterFactory<ValTYpe>(String 
       ParamName, SqlParamInOrOut Direction) where ValTYpe: SqlDbType

This gives the error: "Error 1 'System.Data.SqlDbType' is not a valid constraint. A type used as a constraint must be an interface, a non-sealed class or a type parameter." 这给出了错误:“错误1'System.Data.SqlDbType'不是有效的约束。用作约束的类型必须是接口,未密封的类或类型参数。”

I sense it is doable, but it's my sytax... any help would be appreciated. 我认为这是可行的,但这是我的语法...任何帮助将不胜感激。

SqlDbType is an enum. SqlDbType是一个枚举。 Pass it as a parameter 将其作为参数传递

  private static SqlParameter SqlParameterFactory(SqlDbType ValType, String  
   ParamName, SqlParamInOrOut Direction) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM