Imports System.Runtime.CompilerServices Namespace TaskHost Public Module Extensions ''' ''' Services running on a LAN? ''' Dim _local As Boolean = False ''' ''' 假若这个参数为真,则说明服务只是运行在局域网之中,则只会返回局域网的IP地址 ''' 假若为假,则说明服务是运行在互联网上面的,则会查询主机的公共IP地址,调试的时候建议设置为真 ''' ''' Public Property EnvironmentLocal As Boolean Get Return _local End Get Set(value As Boolean) _local = value If _local Then _IPAddress = Net.AsynInvoke.LocalIPAddress Else _IPAddress = GetMyIPAddress() End If End Set End Property Public ReadOnly Property IPAddress As String Sub New() #If DEBUG Then EnvironmentLocal = True #Else EnvironmentLocal = False #End If End Sub Public ReadOnly Property PublicShared As System.Reflection.BindingFlags = System.Reflection.BindingFlags.Public Or System.Reflection.BindingFlags.Static ''' ''' ''' ''' ''' NameOf ''' Public Function [AddressOf](type As Type, name As String) As InvokeInfo Dim method = type.GetMethod(name, bindingAttr:=PublicShared) Dim info As New InvokeInfo With { .assm = FileIO.FileSystem.GetFileInfo(type.Assembly.Location).Name, .Name = method.Name, .FullIdentity = type.FullName } Return info End Function Public Function Invoke(info As InvokeInfo, host As TaskHost) As Object If host Is Nothing Then Return TaskInvoke.TryInvoke(info) Else Dim rtvl = host.Invoke(info) Dim entry = info.GetMethod Return rtvl.GetValue(entry.ReturnType) End If End Function ''' ''' DirectCast ''' ''' ''' ''' ''' Public Function Invoke(Of T)(info As InvokeInfo, host As TaskHost) As T Return DirectCast(info.Invoke(host), T) End Function Public Function AddressEquals(a As Object, b As Object) As Boolean Return ObjectAddress.AddressOf(a) = b End Function End Module End Namespace