简体   繁体   中英

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. 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."

I sense it is doable, but it's my sytax... any help would be appreciated.

SqlDbType is an enum. Pass it as a parameter

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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