在将项目转换为.NET标准2.0时,FSharpFunc<T, TResult>
。FSharp.Core
库中的FromConverter
方法不再可用。有没有办法把这段代码转换成.NET标准2.0的FSharp.Core
实现?
async Task<Unit> RunProcess(FSharpMailboxProcessor<T> mailbox, Func<T, Task> process) { ... }
public BaseMailboxProcessor(Func<TFuncInput, Task> process, Action<Exception, TFuncInput> errorHandler = null, CancellationToken? cancellationToken = null)
{
m_ErrorHandler = errorHandler;
m_TokenSource = cancellationToken.HasValue ? CancellationTokenSource.CreateLinkedTokenSource(cancellationToken.Value) :
new CancellationTokenSource();
var cancellationOption = FSharpOption<CancellationToken>.Some(m_TokenSource.Token);
Converter<FSharpMailboxProcessor<TMailboxInput>, FSharpAsync<Unit>> converter = (mailbox) =>
{
return FSharpAsync.AwaitTask<Unit>(RunProcess(mailbox, process));
};
m_Mailbox = new FSharpMailboxProcessor<TMailboxInput>(FSharpFunc<FSharpMailboxProcessor<TMailboxInput>, FSharpAsync<Unit>>.FromConverter(converter), cancellationOption);
m_Mailbox.Start();
}
发布于 2018-01-06 03:25:29
您应该能够使用FuncConvert.ToFSharpFunc
,这似乎仍然存在于netstandard版本的FSharp.Core中。
发布于 2018-01-07 00:19:58
你可以简单地定义你自己的:
let ToFSharpFunc (converter: System.Func<_, _>) = fun t -> converter.Invoke t
此外,如果您需要在C#中使用FSharpFunc
,您可以简单地对其调用.Invoke
,其中FSharpFunc
对象上的.Invoke
是一个Func
。
https://stackoverflow.com/questions/48119288
复制相似问题