小编Pet*_*ell的帖子

GetAllNetworkInterfaces()抛出异常

在Mono for Android中,我试图获取本地网络中设备的所有IP地址.

我不介意环回,但我对调用DNS不感兴趣.

最好的方式似乎是打电话......

using System.Net.NetworkInformation;

NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
Run Code Online (Sandbox Code Playgroud)

...除了它抛出......

System.EntryPointNotFoundException:getifaddrs

有什么建议?

c# mono networking android xamarin.android

4
推荐指数
1
解决办法
2256
查看次数

如何获取Delphi中作为泛型参数传递的接口的GUID?

下面,Obtain() 方法有效,但 GetAs() 方法对于调用者来说会更简洁。

但是,我不知道如何将接口作为通用参数传递并获取其 GUID。

宣言:

  TInterfaceRegistry = class
  private
    fRegistry: TDictionary<TGUID, IInterface>;
  public
    ...
    procedure Register(const IID: TGUID; IntfObj: IInterface; const Replace: Boolean = False);
    function  Obtain(const IID: TGUID; out IntfObj): Boolean;
    function  GetAs<I: IInterface>(): I;
  end;
Run Code Online (Sandbox Code Playgroud)

执行:

function TInterfaceRegistry.Obtain(const IID: TGUID; out IntfObj): Boolean;
var
  Found: IInterface;
begin
  Result  := fRegistry.TryGetValue(IID, Found);
  if  Result  then
    if  not Supports(Found, IID, IntfObj) then
      raise EBatSoft.Create(SEBatSoftBug);
end;

function  TInterfaceRegistry.GetAs<I>(): I;
begin
  if  not Obtain(I, Result) then
    raise EBatSoft.Create(SEDoesNotImplement);
end;
Run Code Online (Sandbox Code Playgroud)

调用它看起来像这样...... …

delphi generics interface

2
推荐指数
1
解决办法
302
查看次数

标签 统计

android ×1

c# ×1

delphi ×1

generics ×1

interface ×1

mono ×1

networking ×1

xamarin.android ×1