我正在编写一个适配器类来将 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)