小编Jam*_*mes的帖子

如何在 F# 中一般处理选项值

我正在编写一个适配器类来将 IEnumerable<'T> 映射到 IDataReader,完整的源代码位于https://gist.github.com/jsnape/56f1fb4876974de94238以供参考,但我想问一下编写它的一部分的最佳方法. 即两个函数:

member this.GetValue(ordinal) =
    let value = match enumerator with
        | Some e -> getters.[ordinal](e.Current)
        | None -> raise (new ObjectDisposedException("EnumerableReader"))

    match value with
        | :? Option<string> as x -> if x.IsNone then DBNull.Value :> obj else x.Value :> obj
        | :? Option<int> as x -> if x.IsNone then DBNull.Value :> obj else x.Value :> obj
        | :? Option<decimal> as x -> if x.IsNone then DBNull.Value :> obj else x.Value :> obj
        | :? …
Run Code Online (Sandbox Code Playgroud)

f# idatareader option

4
推荐指数
1
解决办法
1620
查看次数

标签 统计

f# ×1

idatareader ×1

option ×1