在F#匹配语句如何匹配的类型byte []? [英] in f# match statement how do I match to the type byte[]?

查看:113
本文介绍了在F#匹配语句如何匹配的类型byte []?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从.NET类型查找的DbType枚举值。我使用的是匹配语句。不过,我无法弄清楚如何匹配的类型byte []。

I'm trying to lookup DbType enumeration values from .net types. I'm using a match statement. However I cannot figure out how to match on the type 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.

推荐答案

字节[] 字节数组,和阵列和LT;字节> 都是同义的,但在这种情况下只有最后将工作没有括号:

byte[], byte array, and array<byte> are all synonymous, but in this context only the last will work without parentheses:

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

这篇关于在F#匹配语句如何匹配的类型byte []?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆