问题
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#.
One issue I have currently run into is setting SystemTime such as shown in this question, Quartz.net + testing with SystemTime.UtcNow.
I could be wrong, but I thought that the code in F# should be:
SystemTime.Now = fun () -> DateTime(someDate)
SystemTime.UtcNow = fun () -> DateTime(someDate)
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.
回答1:
The single =
is an equality comparison operation. If you want to do assignment, use the <-
assignment operator.
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.))
To invoke them from F# is also a bit more involved:
> 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
来源:https://stackoverflow.com/questions/29705365/quartz-net-and-f-systemtime-and-keymatcher