【发布时间】:2020-04-04 09:07:24
【问题描述】:
给定 F# 中的两个对象,有没有办法使用它们的 IComparable 方法来比较它们,假设它们都是相同的子类型并且 IComparable 是针对它们的公共子类型实现的。
我想用伪代码实现什么:
let tycompare (o1 : obj) (o2 : obj) : int option =
let (ty1, ty2) = (o1.GetType(), o2.GetType())
if ty1 <> ty2 then
None
else
if IComparable is implemented on ty1 then
o1.CompareTo(o2) |> Some
else
None
我知道这个post,但我认为这对直接回答我的问题没有帮助。
【问题讨论】:
标签: reflection f# icomparable