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)
完美的作品,謝謝您。並感謝您的鏈接。 –