访问NativeWifi库中类的类中的方法

时间:2015-03-18 11:06:18

标签: c#

这是关于C#和类的基本用法的问题。我正在尝试让Windows刷新其检测到的访问点列表。所以我试着调用方法scan()(参见底部的代码)。它是类中类的一个方法,所以我试着像这样调用它......

var v1 = new WlanClient.WlanInterface(); //Error 'NativeWifi.WlanClient.WlanInterface' has no constructors defined
v1.Scan();

就像这样......

WlanClient.WlanInterface.Scan();  //Error An object reference is required for the non-static field, method, or property 

关于这类事情的类似答案表明它与内部属性有关,但我不明白这是否与我相关。

namespace NativeWifi
{
    public class WlanClient
    {
        public WlanClient();

        public WlanClient.WlanInterface[] Interfaces { get; }

        public string GetStringForReasonCode(Wlan.WlanReasonCode reasonCode);

        public class WlanInterface
        {
            public bool Autoconf { get; set; }
            public Wlan.Dot11BssType BssType { get; set; }
            public int Channel { get; }
            public Wlan.WlanConnectionAttributes CurrentConnection { get; }
            public Wlan.Dot11OperationMode CurrentOperationMode { get; }
            public string InterfaceDescription { get; }
            public Guid InterfaceGuid { get; }
            public string InterfaceName { get; }
            public Wlan.WlanInterfaceState InterfaceState { get; }
            public NetworkInterface NetworkInterface { get; }
            public int RSSI { get; }

            public event WlanClient.WlanInterface.WlanConnectionNotificationEventHandler WlanConnectionNotification;
            public event WlanClient.WlanInterface.WlanNotificationEventHandler WlanNotification;
            public event WlanClient.WlanInterface.WlanReasonNotificationEventHandler WlanReasonNotification;

            protected void Connect(Wlan.WlanConnectionParameters connectionParams);
            public void Connect(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, string profile);
            public void Connect(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, Wlan.Dot11Ssid ssid, Wlan.WlanConnectionFlags flags);
            public bool ConnectSynchronously(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, string profile, int connectTimeout);
            public void DeleteProfile(string profileName);
            public Wlan.WlanAvailableNetwork[] GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags flags);
            public Wlan.WlanBssEntry[] GetNetworkBssList();
            public Wlan.WlanBssEntry[] GetNetworkBssList(Wlan.Dot11Ssid ssid, Wlan.Dot11BssType bssType, bool securityEnabled);
            public Wlan.WlanProfileInfo[] GetProfiles();
            public string GetProfileXml(string profileName);
            public void Scan();
            public Wlan.WlanReasonCode SetProfile(Wlan.WlanProfileFlags flags, string profileXml, bool overwrite);

            public delegate void WlanConnectionNotificationEventHandler(Wlan.WlanNotificationData notifyData, Wlan.WlanConnectionNotificationData connNotifyData);

            public delegate void WlanNotificationEventHandler(Wlan.WlanNotificationData notifyData);

            public delegate void WlanReasonNotificationEventHandler(Wlan.WlanNotificationData notifyData, Wlan.WlanReasonCode reasonCode);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

要查看可用Wifi接口的状态,请使用:

var client = new WlanClient();
foreach(var wifiInterface in  wifi.Interfaces)
{
    Console.WriteLine("{0} {1}", wifiInterface.InterfaceName, 
                                 wifiInterface.InterfaceState);
}

要扫描第一个界面,请使用:

var client = new WlanClient();
var wifiInterface = client.Interfaces.First();
wifiInterface.Scan()