问题描述
我正在尝试在F#中使用Quartz.NET,但遇到了一些问题,尽管Quartz.NET在F#中可用,但似乎没有太多文档,而且我已经
I am trying to work with Quartz.NET in F# and have run into a few issues with the fact that, while Quartz.NET is usable in F#, there does not seem to be much documentation on it, and I've had some difficulty with differences between it and what can find in C#.
我目前遇到的一个问题是设置SystemTime,如该问题所示,
。
One issue I have currently run into is setting SystemTime such as shown in this question,Quartz.net + testing with SystemTime.UtcNow.
我可能是错的,但是我认为F#中的代码应该是:
I could be wrong, but I thought that the code in F# should be:
SystemTime.Now = fun () -> DateTime(someDate)
SystemTime.UtcNow = fun () -> DateTime(someDate)
但是我收到关于在预期之外使用的过多参数或函数的错误。如果仅使用DateTime构造函数,则会收到与它期望函数的事实有关的错误。
But I get an error about either too many arguments or function used where not expected. If I just use the DateTime constructor, I get an error related to the fact it is expecting a function.
推荐答案
单个 =
是一个相等比较操作。如果要进行赋值,请使用<-
赋值运算符。
The single =
is an equality comparison operation. If you want to do assignment, use the <-
assignment operator.
此外,F#函数与 Func< T>
相同。通常,当您将它们用作方法参数时,转换会自动发生,但是在这种情况下,您似乎需要显式执行转换:
Apart from that, F# functions aren't the same as Func<T>
. Normally, when you use them as method arguments, the conversion happens automatically, but in this case, it seems you'll need to explicitly perform the conversion:
open System
open Quartz
SystemTime.Now <-
Func<DateTimeOffset>(
fun () -> DateTimeOffset(DateTime(2015, 4, 18), TimeSpan.FromHours 2.))
SystemTime.UtcNow <-
Func<DateTimeOffset>(
fun () -> DateTimeOffset(DateTime(2015, 4, 18), TimeSpan.FromHours 2.))
从F#调用它们也有点
> SystemTime.Now.Invoke();;
val it : DateTimeOffset = 18.04.2015 00:00:00 +02:00
> SystemTime.UtcNow.Invoke();;
val it : DateTimeOffset = 18.04.2015 00:00:00 +02:00
这篇关于Quartz.NET和F#-SystemTime和KeyMatcher的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!