3
我写一个使用Quartz.Net以轮询其他服务(已经用C#编写)的F#服务:与DateTime.MinValue匹配的模式?
[<PersistJobDataAfterExecution>]
[<DisallowConcurrentExecution>]
type PollingJob() =
interface IJob with
member x.Execute(context: IJobExecutionContext) =
let uri = "http://localhost:8089/"
let storedDate = context.JobDetail.JobDataMap.GetDateTime("LastPoll")
//this works...
let effectiveFrom = (if storedDate = DateTime.MinValue then System.Nullable() else System.Nullable(storedDate))
let result = someFunction uri effectiveFrom
context.JobDetail.JobDataMap.Put("LastPoll", DateTime.UtcNow) |> ignore
的context
传递给Execute
功能由石英为每个投票和包含字典。服务第一次运行时,LastPoll
的值将为默认的DateTime
值,即01/01/0001 00:00:00
。然后下一次调度程序运行LastPoll
将包含上次轮询的时间。
我可以使用if..then..else
结构(上图)创建Nullable<DateTime>
但是当我尝试使用模式匹配我得到一个编译错误与波浪线下DateTime.MinValue
:
这个字段是不是文字,不能在图案中使用
我想使用的代码如下:
//this doesn't...
let effectiveFrom =
match storedDate with
| DateTime.MinValue -> System.Nullable()
| _ -> System.Nullable(storedDate)
完美的作品,谢谢您。并感谢您的链接。 –