[英]in f# match statement how do I match to the type byte[]?
I'm trying to lookup DbType enumeration values from .net types. 我正在尝试从.net类型中查找DbType枚举值。 I'm using a match statement. 我正在使用match语句。 However I cannot figure out how to match on the type byte[]. 但是,我不知道如何在类型byte []上进行匹配。
let dbType x =
match x with
| :? Int64 -> DbType.Int64
| :? Byte[] -> DbType.Binary // this gives an error
| _ -> DbType.Object
If there is a better way to map these types, I would be open to suggestions. 如果有更好的方法来映射这些类型,我会提出建议。
byte[]
, byte array
, and array<byte>
are all synonymous, but in this context only the last will work without parentheses: byte[]
, byte array
和array<byte>
都是同义词,但是在这种情况下,只有最后一个可以不带括号:
let dbType (x:obj) =
match x with
| :? (byte[]) -> DbType.Binary
| :? (byte array) -> DbType.Binary // equivalent to above
| :? array<byte> -> DbType.Binary // equivalent to above
| :? int64 -> DbType.Int64
| _ -> DbType.Object
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.