嗨,我在f#中有一个扩展方法,它检查是否已连接TcpClinet,这是相当简单的代码:
[<Extension>]
type TcpExtension() =
[<Extension>]
static member inline IsConnectionEstablished(client: TcpClient) : bool =
let ipProperties : IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
let tcpConnection : Option<TcpConnectionInformation> = ipProperties.GetActiveTcpConnections() |> Seq.tryFind(fun connection -> connection.LocalEndPoint.Equals(client.Client.LocalEndPoint) && connection.RemoteEndPoint.Equals(client.Client.RemoteEndPoint))
match tcpConnection with
| Some connection -> true
| None -> false
现在我想简单地使用它:
let private WaitForData (client : TcpClient) =
let isConnectionAlive : bool = client.IsConnectionEstablished
isConnectionAlive
但是我收到的消息如下:
此函数接受了太多参数,或者在不需要该函数的上下文中使用
当我查看Microsoft文档时,这就是他们表示应该对其进行处理的方式,我在这里遗漏了什么?
答案 0 :(得分:3)
错误消息有点令人误解,您实际上是缺少一个参数
要调用该函数,您需要传递unit
,就像从C#调用它一样
let isConnectionAlive : bool = client.IsConnectionEstablished()