From 54e3d38e4948fe3c285cf1a7bda0277f3b28e0df Mon Sep 17 00:00:00 2001 From: buyaa-n Date: Mon, 9 Mar 2020 15:02:21 -0700 Subject: [PATCH] Annotate System.Net.NetworkInformation for nullable (#32990) * Annotate System.Net.NetworkInformation for nullable --- .../Interop.EnumerateInterfaceAddresses.cs | 4 +- .../Common/src/System/IO/RowConfigReader.cs | 7 +-- .../Common/src/System/Net/ContextAwareResult.cs | 2 +- .../ref/System.Net.NetworkInformation.cs | 20 ++++---- .../ref/System.Net.NetworkInformation.csproj | 1 + .../src/System.Net.NetworkInformation.csproj | 1 + .../Net/NetworkInformation/BsdNetworkInterface.cs | 4 +- .../Net/NetworkInformation/IPGlobalProperties.cs | 2 +- .../NetworkInformation/IPInterfaceProperties.cs | 2 +- .../NetworkInformation/LinuxNetworkInterface.cs | 12 ++--- .../NetworkInformation/NetworkAddressChange.OSX.cs | 30 +++++------ .../NetworkAddressChange.Unix.cs | 26 +++++----- .../NetworkAddressChange.UnknownUnix.cs | 4 +- .../NetworkAddressChange.Windows.cs | 58 +++++++++++----------- .../Net/NetworkInformation/NetworkAddressChange.cs | 14 +++--- .../NetworkInformation/NetworkChangeDelegates.cs | 4 +- .../Net/NetworkInformation/PhysicalAddress.cs | 15 +++--- .../StringParsingHelpers.Addresses.cs | 3 +- .../NetworkInformation/StringParsingHelpers.Dns.cs | 10 ++-- .../StringParsingHelpers.Statistics.cs | 2 +- .../NetworkInformation/SystemIPGlobalProperties.cs | 6 +-- .../SystemIPInterfaceProperties.cs | 16 +++--- .../NetworkInformation/SystemNetworkInterface.cs | 2 +- .../SystemUnicastIPAddressInformation.cs | 4 +- .../System/Net/NetworkInformation/TeredoHelper.cs | 6 +-- .../NetworkInformation/UnixIPGlobalProperties.cs | 4 +- .../UnixIPInterfaceProperties.cs | 12 ++--- .../Net/NetworkInformation/UnixNetworkInterface.cs | 4 +- 28 files changed, 139 insertions(+), 136 deletions(-) diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs index 8e03a33..7ad346a 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs @@ -51,8 +51,8 @@ internal static partial class Interop [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_EnumerateInterfaceAddresses")] public static extern int EnumerateInterfaceAddresses( IPv4AddressDiscoveredCallback ipv4Found, - IPv6AddressDiscoveredCallback ipv6Found, - LinkLayerAddressDiscoveredCallback linkLayerFound); + IPv6AddressDiscoveredCallback? ipv6Found, + LinkLayerAddressDiscoveredCallback? linkLayerFound); [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_EnumerateGatewayAddressesForInterface")] public static extern int EnumerateGatewayAddressesForInterface(uint interfaceIndex, DnsAddessDiscoveredCallback onGatewayFound); diff --git a/src/libraries/Common/src/System/IO/RowConfigReader.cs b/src/libraries/Common/src/System/IO/RowConfigReader.cs index fcd9d10..b59fe76 100644 --- a/src/libraries/Common/src/System/IO/RowConfigReader.cs +++ b/src/libraries/Common/src/System/IO/RowConfigReader.cs @@ -2,7 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; namespace System.IO @@ -47,8 +49,7 @@ namespace System.IO /// public string GetNextValue(string key) { - string value; - if (!TryGetNextValue(key, out value)) + if (!TryGetNextValue(key, out string? value)) { throw new InvalidOperationException("Couldn't get next value with key " + key); } @@ -62,7 +63,7 @@ namespace System.IO /// Tries to get the next occurrence of the given key from the current position of the reader. /// If successful, returns true and stores the result in 'value'. Otherwise, returns false. /// - public bool TryGetNextValue(string key, out string value) + public bool TryGetNextValue(string key, [NotNullWhen(true)] out string? value) { Debug.Assert(_buffer != null); if (_currentIndex >= _buffer.Length) diff --git a/src/libraries/Common/src/System/Net/ContextAwareResult.cs b/src/libraries/Common/src/System/Net/ContextAwareResult.cs index b143be3..bf8942c 100644 --- a/src/libraries/Common/src/System/Net/ContextAwareResult.cs +++ b/src/libraries/Common/src/System/Net/ContextAwareResult.cs @@ -24,7 +24,7 @@ namespace System.Net private readonly AsyncCallback? _savedCallback; private readonly ExecutionContext? _savedContext; - internal CallbackClosure(ExecutionContext context, AsyncCallback callback) + internal CallbackClosure(ExecutionContext context, AsyncCallback? callback) { if (callback != null) { diff --git a/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs b/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs index 44a97a6..f932862 100644 --- a/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs +++ b/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs @@ -129,7 +129,7 @@ namespace System.Net.NetworkInformation public abstract string HostName { get; } public abstract bool IsWinsProxy { get; } public abstract System.Net.NetworkInformation.NetBiosNodeType NodeType { get; } - public virtual System.IAsyncResult BeginGetUnicastAddresses(System.AsyncCallback callback, object state) { throw null; } + public virtual System.IAsyncResult BeginGetUnicastAddresses(System.AsyncCallback? callback, object? state) { throw null; } public virtual System.Net.NetworkInformation.UnicastIPAddressInformationCollection EndGetUnicastAddresses(System.IAsyncResult asyncResult) { throw null; } public abstract System.Net.NetworkInformation.TcpConnectionInformation[] GetActiveTcpConnections(); public abstract System.Net.IPEndPoint[] GetActiveTcpListeners(); @@ -185,7 +185,7 @@ namespace System.Net.NetworkInformation public abstract System.Net.NetworkInformation.MulticastIPAddressInformationCollection MulticastAddresses { get; } public abstract System.Net.NetworkInformation.UnicastIPAddressInformationCollection UnicastAddresses { get; } public abstract System.Net.NetworkInformation.IPAddressCollection WinsServersAddresses { get; } - public abstract System.Net.NetworkInformation.IPv4InterfaceProperties GetIPv4Properties(); + public abstract System.Net.NetworkInformation.IPv4InterfaceProperties? GetIPv4Properties(); public abstract System.Net.NetworkInformation.IPv6InterfaceProperties GetIPv6Properties(); } public abstract partial class IPInterfaceStatistics @@ -270,8 +270,8 @@ namespace System.Net.NetworkInformation Mixed = 4, Hybrid = 8, } - public delegate void NetworkAddressChangedEventHandler(object sender, System.EventArgs e); - public delegate void NetworkAvailabilityChangedEventHandler(object sender, System.Net.NetworkInformation.NetworkAvailabilityEventArgs e); + public delegate void NetworkAddressChangedEventHandler(object? sender, System.EventArgs e); + public delegate void NetworkAvailabilityChangedEventHandler(object? sender, System.Net.NetworkInformation.NetworkAvailabilityEventArgs e); public partial class NetworkAvailabilityEventArgs : System.EventArgs { internal NetworkAvailabilityEventArgs() { } @@ -282,8 +282,8 @@ namespace System.Net.NetworkInformation [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] [System.ObsoleteAttribute("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)] public NetworkChange() { } - public static event System.Net.NetworkInformation.NetworkAddressChangedEventHandler NetworkAddressChanged { add { } remove { } } - public static event System.Net.NetworkInformation.NetworkAvailabilityChangedEventHandler NetworkAvailabilityChanged { add { } remove { } } + public static event System.Net.NetworkInformation.NetworkAddressChangedEventHandler? NetworkAddressChanged { add { } remove { } } + public static event System.Net.NetworkInformation.NetworkAvailabilityChangedEventHandler? NetworkAvailabilityChanged { add { } remove { } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] [System.ObsoleteAttribute("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)] public static void RegisterNetworkChange(System.Net.NetworkInformation.NetworkChange nc) { } @@ -366,13 +366,13 @@ namespace System.Net.NetworkInformation { public static readonly System.Net.NetworkInformation.PhysicalAddress None; public PhysicalAddress(byte[] address) { } - public override bool Equals(object comparand) { throw null; } + public override bool Equals(object? comparand) { throw null; } public byte[] GetAddressBytes() { throw null; } public override int GetHashCode() { throw null; } - public static System.Net.NetworkInformation.PhysicalAddress Parse(string address) { throw null; } + public static System.Net.NetworkInformation.PhysicalAddress Parse(string? address) { throw null; } public static System.Net.NetworkInformation.PhysicalAddress Parse(ReadOnlySpan address) { throw null; } - public static bool TryParse(string address, out System.Net.NetworkInformation.PhysicalAddress value) { throw null; } - public static bool TryParse(ReadOnlySpan address, out System.Net.NetworkInformation.PhysicalAddress value) { throw null; } + public static bool TryParse(string? address, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Net.NetworkInformation.PhysicalAddress? value) { throw null; } + public static bool TryParse(ReadOnlySpan address, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Net.NetworkInformation.PhysicalAddress? value) { throw null; } public override string ToString() { throw null; } } public enum PrefixOrigin diff --git a/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.csproj b/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.csproj index 1887199..2718a27 100644 --- a/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.csproj +++ b/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.csproj @@ -1,6 +1,7 @@ $(NetCoreAppCurrent) + enable diff --git a/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj b/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj index 4a65f9e..3925af4 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj +++ b/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj @@ -5,6 +5,7 @@ true $(NoWarn);CA1823 $(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-FreeBSD + enable diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BsdNetworkInterface.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BsdNetworkInterface.cs index da3e335..e206ca1 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BsdNetworkInterface.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BsdNetworkInterface.cs @@ -39,7 +39,7 @@ namespace System.Net.NetworkInformation public static unsafe NetworkInterface[] GetBsdNetworkInterfaces() { Dictionary interfacesByName = new Dictionary(); - List exceptions = null; + List? exceptions = null; const int MaxTries = 3; for (int attempt = 0; attempt < MaxTries; attempt++) { @@ -128,7 +128,7 @@ namespace System.Net.NetworkInformation /// The cached or new BsdNetworkInterface with the given name. private static BsdNetworkInterface GetOrCreate(Dictionary interfaces, string name, int index) { - BsdNetworkInterface oni; + BsdNetworkInterface? oni; if (!interfaces.TryGetValue(name, out oni)) { oni = new BsdNetworkInterface(name, index); diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalProperties.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalProperties.cs index e7f55e6..b45d8be 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalProperties.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPGlobalProperties.cs @@ -57,7 +57,7 @@ namespace System.Net.NetworkInformation /// public abstract NetBiosNodeType NodeType { get; } - public virtual IAsyncResult BeginGetUnicastAddresses(AsyncCallback callback, object state) + public virtual IAsyncResult BeginGetUnicastAddresses(AsyncCallback? callback, object? state) { throw NotImplemented.ByDesignWithMessage(SR.net_MethodNotImplementedException); } diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPInterfaceProperties.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPInterfaceProperties.cs index ede5be7..2f9fdaf 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPInterfaceProperties.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPInterfaceProperties.cs @@ -64,7 +64,7 @@ namespace System.Net.NetworkInformation /// Gets the IP version 4.0 specific properties for this network interface. /// /// The interface' IPv4-specific properties. - public abstract IPv4InterfaceProperties GetIPv4Properties(); + public abstract IPv4InterfaceProperties? GetIPv4Properties(); /// /// Gets the IP version 6.0 specific properties for this network interface. diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/LinuxNetworkInterface.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/LinuxNetworkInterface.cs index 77c53cf..1eb2f99 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/LinuxNetworkInterface.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/LinuxNetworkInterface.cs @@ -23,10 +23,10 @@ namespace System.Net.NetworkInformation internal class LinuxNetworkInterfaceSystemProperties { - internal string[] IPv4Routes; - internal string[] IPv6Routes; - internal string DnsSuffix; - internal IPAddressCollection DnsAddresses; + internal string[]? IPv4Routes; + internal string[]? IPv6Routes; + internal string? DnsSuffix; + internal IPAddressCollection? DnsAddresses; internal LinuxNetworkInterfaceSystemProperties() { @@ -82,7 +82,7 @@ namespace System.Net.NetworkInformation for (int i = 0; i < interfaceCount; i++) { - var lni = new LinuxNetworkInterface(Marshal.PtrToStringAnsi((IntPtr)nii->Name), nii->InterfaceIndex, systemProperties); + var lni = new LinuxNetworkInterface(Marshal.PtrToStringAnsi((IntPtr)nii->Name)!, nii->InterfaceIndex, systemProperties); lni._interfaceType = (NetworkInterfaceType)nii->HardwareType; lni._speed = nii->Speed; lni._operationalStatus = (OperationalStatus)nii->OperationalState; @@ -102,7 +102,7 @@ namespace System.Net.NetworkInformation address.ScopeId = ai->InterfaceIndex; } - if (interfacesByIndex.TryGetValue(ai->InterfaceIndex, out LinuxNetworkInterface lni)) + if (interfacesByIndex.TryGetValue(ai->InterfaceIndex, out LinuxNetworkInterface? lni)) { lni.AddAddress(address, ai->PrefixLength); } diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs index cf0655c..8ebc1c2 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs @@ -21,16 +21,16 @@ namespace System.Net.NetworkInformation // The dynamic store. We listen to changes in the IPv4 and IPv6 address keys. // When those keys change, our callback below is called (OnAddressChanged). - private static SafeCreateHandle s_dynamicStoreRef; + private static SafeCreateHandle? s_dynamicStoreRef; // The callback used when registered keys in the dynamic store change. private static readonly Interop.SystemConfiguration.SCDynamicStoreCallBack s_storeCallback = OnAddressChanged; // The RunLoop source, created over the above SCDynamicStore. - private static SafeCreateHandle s_runLoopSource; + private static SafeCreateHandle? s_runLoopSource; // Listener thread that adds the RunLoopSource to its RunLoop. - private static Thread s_runLoopThread; + private static Thread? s_runLoopThread; // The listener thread's CFRunLoop. private static CFRunLoopRef s_runLoop; @@ -41,7 +41,7 @@ namespace System.Net.NetworkInformation private static readonly AutoResetEvent s_runLoopStartedEvent = new AutoResetEvent(false); private static readonly AutoResetEvent s_runLoopEndedEvent = new AutoResetEvent(false); - public static event NetworkAddressChangedEventHandler NetworkAddressChanged + public static event NetworkAddressChangedEventHandler? NetworkAddressChanged { add { @@ -78,7 +78,7 @@ namespace System.Net.NetworkInformation } } - public static event NetworkAvailabilityChangedEventHandler NetworkAvailabilityChanged + public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityChanged { add { @@ -193,7 +193,7 @@ namespace System.Net.NetworkInformation s_runLoop = Interop.RunLoop.CFRunLoopGetCurrent(); Interop.RunLoop.CFRunLoopAddSource( s_runLoop, - s_runLoopSource.DangerousGetHandle(), + s_runLoopSource!.DangerousGetHandle(), Interop.RunLoop.kCFRunLoopDefaultMode.DangerousGetHandle()); s_runLoopStartedEvent.Set(); @@ -209,7 +209,7 @@ namespace System.Net.NetworkInformation s_runLoopSource.Dispose(); s_runLoopSource = null; - s_dynamicStoreRef.Dispose(); + s_dynamicStoreRef!.Dispose(); s_dynamicStoreRef = null; s_runLoopEndedEvent.Set(); @@ -230,28 +230,28 @@ namespace System.Net.NetworkInformation private static void OnAddressChanged(IntPtr store, IntPtr changedKeys, IntPtr info) { - Dictionary addressChangedSubscribers = null; - Dictionary availabilityChangedSubscribers = null; + Dictionary? addressChangedSubscribers = null; + Dictionary? availabilityChangedSubscribers = null; lock (s_lockObj) { if (s_addressChangedSubscribers.Count > 0) { - addressChangedSubscribers = new Dictionary(s_addressChangedSubscribers); + addressChangedSubscribers = new Dictionary(s_addressChangedSubscribers); } if (s_availabilityChangedSubscribers.Count > 0) { - availabilityChangedSubscribers = new Dictionary(s_availabilityChangedSubscribers); + availabilityChangedSubscribers = new Dictionary(s_availabilityChangedSubscribers); } } if (addressChangedSubscribers != null) { - foreach (KeyValuePair + foreach (KeyValuePair subscriber in addressChangedSubscribers) { NetworkAddressChangedEventHandler handler = subscriber.Key; - ExecutionContext ec = subscriber.Value; + ExecutionContext? ec = subscriber.Value; if (ec == null) // Flow supressed { @@ -269,11 +269,11 @@ namespace System.Net.NetworkInformation bool isAvailable = NetworkInterface.GetIsNetworkAvailable(); NetworkAvailabilityEventArgs args = isAvailable ? s_availableEventArgs : s_notAvailableEventArgs; ContextCallback callbackContext = isAvailable ? s_runHandlerAvailable : s_runHandlerNotAvailable; - foreach (KeyValuePair + foreach (KeyValuePair subscriber in availabilityChangedSubscribers) { NetworkAvailabilityChangedEventHandler handler = subscriber.Key; - ExecutionContext ec = subscriber.Value; + ExecutionContext? ec = subscriber.Value; if (ec == null) // Flow supressed { diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Unix.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Unix.cs index b5211c3..dce7f09 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Unix.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Unix.cs @@ -24,10 +24,10 @@ namespace System.Net.NetworkInformation // has potentially changed as a result. private const int AvailabilityTimerWindowMilliseconds = 150; private static readonly TimerCallback s_availabilityTimerFiredCallback = OnAvailabilityTimerFired; - private static Timer s_availabilityTimer; + private static Timer? s_availabilityTimer; private static bool s_availabilityHasChanged; - public static event NetworkAddressChangedEventHandler NetworkAddressChanged + public static event NetworkAddressChangedEventHandler? NetworkAddressChanged { add { @@ -67,7 +67,7 @@ namespace System.Net.NetworkInformation } } - public static event NetworkAvailabilityChangedEventHandler NetworkAvailabilityChanged + public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityChanged { add { @@ -151,7 +151,7 @@ namespace System.Net.NetworkInformation } s_socket = newSocket; - Task.Factory.StartNew(s => LoopReadSocket((int)s), s_socket, + Task.Factory.StartNew(s => LoopReadSocket((int)s!), s_socket, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default); } @@ -216,23 +216,23 @@ namespace System.Net.NetworkInformation private static void OnAddressChanged() { - Dictionary addressChangedSubscribers = null; + Dictionary? addressChangedSubscribers = null; lock (s_gate) { if (s_addressChangedSubscribers.Count > 0) { - addressChangedSubscribers = new Dictionary(s_addressChangedSubscribers); + addressChangedSubscribers = new Dictionary(s_addressChangedSubscribers); } } if (addressChangedSubscribers != null) { - foreach (KeyValuePair + foreach (KeyValuePair subscriber in addressChangedSubscribers) { NetworkAddressChangedEventHandler handler = subscriber.Key; - ExecutionContext ec = subscriber.Value; + ExecutionContext? ec = subscriber.Value; if (ec == null) // Flow supressed { @@ -246,9 +246,9 @@ namespace System.Net.NetworkInformation } } - private static void OnAvailabilityTimerFired(object state) + private static void OnAvailabilityTimerFired(object? state) { - Dictionary availabilityChangedSubscribers = null; + Dictionary? availabilityChangedSubscribers = null; lock (s_gate) { @@ -258,7 +258,7 @@ namespace System.Net.NetworkInformation if (s_availabilityChangedSubscribers.Count > 0) { availabilityChangedSubscribers = - new Dictionary( + new Dictionary( s_availabilityChangedSubscribers); } } @@ -270,11 +270,11 @@ namespace System.Net.NetworkInformation NetworkAvailabilityEventArgs args = isAvailable ? s_availableEventArgs : s_notAvailableEventArgs; ContextCallback callbackContext = isAvailable ? s_runHandlerAvailable : s_runHandlerNotAvailable; - foreach (KeyValuePair + foreach (KeyValuePair subscriber in availabilityChangedSubscribers) { NetworkAvailabilityChangedEventHandler handler = subscriber.Key; - ExecutionContext ec = subscriber.Value; + ExecutionContext? ec = subscriber.Value; if (ec == null) // Flow supressed { diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.UnknownUnix.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.UnknownUnix.cs index 79f8037..4e6e4f6 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.UnknownUnix.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.UnknownUnix.cs @@ -6,13 +6,13 @@ namespace System.Net.NetworkInformation { public partial class NetworkChange { - public static event NetworkAddressChangedEventHandler NetworkAddressChanged + public static event NetworkAddressChangedEventHandler? NetworkAddressChanged { add { throw new PlatformNotSupportedException(); } remove { throw new PlatformNotSupportedException(); } } - public static event NetworkAvailabilityChangedEventHandler NetworkAvailabilityChanged + public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityChanged { add { throw new PlatformNotSupportedException(); } remove { throw new PlatformNotSupportedException(); } diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Windows.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Windows.cs index b70d5a9..6ccb5e6 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Windows.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.Windows.cs @@ -14,7 +14,7 @@ namespace System.Net.NetworkInformation { private static readonly object s_globalLock = new object(); - public static event NetworkAvailabilityChangedEventHandler NetworkAvailabilityChanged + public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityChanged { add { @@ -26,7 +26,7 @@ namespace System.Net.NetworkInformation } } - public static event NetworkAddressChangedEventHandler NetworkAddressChanged + public static event NetworkAddressChangedEventHandler? NetworkAddressChanged { add { @@ -43,9 +43,9 @@ namespace System.Net.NetworkInformation private static readonly NetworkAddressChangedEventHandler s_addressChange = ChangedAddress; private static volatile bool s_isAvailable = false; - private static void ChangedAddress(object sender, EventArgs eventArgs) + private static void ChangedAddress(object? sender, EventArgs eventArgs) { - Dictionary availabilityChangedSubscribers = null; + Dictionary? availabilityChangedSubscribers = null; lock (s_globalLock) { @@ -58,7 +58,7 @@ namespace System.Net.NetworkInformation if (s_availabilityChangedSubscribers.Count > 0) { - availabilityChangedSubscribers = new Dictionary(s_availabilityChangedSubscribers); + availabilityChangedSubscribers = new Dictionary(s_availabilityChangedSubscribers); } } } @@ -70,11 +70,11 @@ namespace System.Net.NetworkInformation NetworkAvailabilityEventArgs args = isAvailable ? s_availableEventArgs : s_notAvailableEventArgs; ContextCallback callbackContext = isAvailable ? s_runHandlerAvailable : s_runHandlerNotAvailable; - foreach (KeyValuePair + foreach (KeyValuePair subscriber in availabilityChangedSubscribers) { NetworkAvailabilityChangedEventHandler handler = subscriber.Key; - ExecutionContext ec = subscriber.Value; + ExecutionContext? ec = subscriber.Value; if (ec == null) // Flow supressed { @@ -88,7 +88,7 @@ namespace System.Net.NetworkInformation } } - internal static void Start(NetworkAvailabilityChangedEventHandler caller) + internal static void Start(NetworkAvailabilityChangedEventHandler? caller) { if (caller != null) { @@ -105,7 +105,7 @@ namespace System.Net.NetworkInformation } } - internal static void Stop(NetworkAvailabilityChangedEventHandler caller) + internal static void Stop(NetworkAvailabilityChangedEventHandler? caller) { if (caller != null) { @@ -127,15 +127,15 @@ namespace System.Net.NetworkInformation // Need to keep the reference so it isn't GC'd before the native call executes. private static bool s_isListening = false; private static bool s_isPending = false; - private static Socket s_ipv4Socket = null; - private static Socket s_ipv6Socket = null; - private static WaitHandle s_ipv4WaitHandle = null; - private static WaitHandle s_ipv6WaitHandle = null; + private static Socket? s_ipv4Socket = null; + private static Socket? s_ipv6Socket = null; + private static WaitHandle? s_ipv4WaitHandle = null; + private static WaitHandle? s_ipv6WaitHandle = null; // Callback fired when an address change occurs. - private static void AddressChangedCallback(object stateObject, bool signaled) + private static void AddressChangedCallback(object? stateObject, bool signaled) { - Dictionary addressChangedSubscribers = null; + Dictionary? addressChangedSubscribers = null; lock (s_globalLock) { @@ -152,13 +152,13 @@ namespace System.Net.NetworkInformation // Need to copy the array so the callback can call start and stop if (s_addressChangedSubscribers.Count > 0) { - addressChangedSubscribers = new Dictionary(s_addressChangedSubscribers); + addressChangedSubscribers = new Dictionary(s_addressChangedSubscribers); } try { //wait for the next address change - StartHelper(null, false, (StartIPOptions)stateObject); + StartHelper(null, false, (StartIPOptions)stateObject!); } catch (NetworkInformationException nie) { @@ -169,11 +169,11 @@ namespace System.Net.NetworkInformation // Release the lock before calling into user callback. if (addressChangedSubscribers != null) { - foreach (KeyValuePair + foreach (KeyValuePair subscriber in addressChangedSubscribers) { NetworkAddressChangedEventHandler handler = subscriber.Key; - ExecutionContext ec = subscriber.Value; + ExecutionContext? ec = subscriber.Value; if (ec == null) // Flow supressed { @@ -187,17 +187,17 @@ namespace System.Net.NetworkInformation } } - internal static void Start(NetworkAddressChangedEventHandler caller) + internal static void Start(NetworkAddressChangedEventHandler? caller) { StartHelper(caller, true, StartIPOptions.Both); } - internal static void UnsafeStart(NetworkAddressChangedEventHandler caller) + internal static void UnsafeStart(NetworkAddressChangedEventHandler? caller) { StartHelper(caller, false, StartIPOptions.Both); } - private static void StartHelper(NetworkAddressChangedEventHandler caller, bool captureContext, StartIPOptions startIPOptions) + private static void StartHelper(NetworkAddressChangedEventHandler? caller, bool captureContext, StartIPOptions startIPOptions) { lock (s_globalLock) { @@ -233,14 +233,14 @@ namespace System.Net.NetworkInformation if (Socket.OSSupportsIPv4 && (startIPOptions & StartIPOptions.StartIPv4) != 0) { ThreadPool.RegisterWaitForSingleObject( - s_ipv4WaitHandle, + s_ipv4WaitHandle!, new WaitOrTimerCallback(AddressChangedCallback), StartIPOptions.StartIPv4, -1, true); SocketError errorCode = Interop.Winsock.WSAIoctl_Blocking( - s_ipv4Socket.SafeHandle, + s_ipv4Socket!.SafeHandle, (int)IOControlCode.AddressListChange, null, 0, null, 0, out int length, @@ -257,7 +257,7 @@ namespace System.Net.NetworkInformation errorCode = Interop.Winsock.WSAEventSelect( s_ipv4Socket.SafeHandle, - s_ipv4WaitHandle.GetSafeWaitHandle(), + s_ipv4WaitHandle!.GetSafeWaitHandle(), Interop.Winsock.AsyncEventBits.FdAddressListChange); if (errorCode != SocketError.Success) @@ -269,14 +269,14 @@ namespace System.Net.NetworkInformation if (Socket.OSSupportsIPv6 && (startIPOptions & StartIPOptions.StartIPv6) != 0) { ThreadPool.RegisterWaitForSingleObject( - s_ipv6WaitHandle, + s_ipv6WaitHandle!, new WaitOrTimerCallback(AddressChangedCallback), StartIPOptions.StartIPv6, -1, true); SocketError errorCode = Interop.Winsock.WSAIoctl_Blocking( - s_ipv6Socket.SafeHandle, + s_ipv6Socket!.SafeHandle, (int)IOControlCode.AddressListChange, null, 0, null, 0, out int length, @@ -293,7 +293,7 @@ namespace System.Net.NetworkInformation errorCode = Interop.Winsock.WSAEventSelect( s_ipv6Socket.SafeHandle, - s_ipv6WaitHandle.GetSafeWaitHandle(), + s_ipv6WaitHandle!.GetSafeWaitHandle(), Interop.Winsock.AsyncEventBits.FdAddressListChange); if (errorCode != SocketError.Success) @@ -308,7 +308,7 @@ namespace System.Net.NetworkInformation } } - internal static void Stop(NetworkAddressChangedEventHandler caller) + internal static void Stop(NetworkAddressChangedEventHandler? caller) { if (caller != null) { diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.cs index aa1c511..06be964 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.cs @@ -10,18 +10,18 @@ namespace System.Net.NetworkInformation public partial class NetworkChange { // The list of current address-changed subscribers. - private static readonly Dictionary s_addressChangedSubscribers = - new Dictionary(); + private static readonly Dictionary s_addressChangedSubscribers = + new Dictionary(); // The list of current availability-changed subscribers. - private static readonly Dictionary s_availabilityChangedSubscribers = - new Dictionary(); + private static readonly Dictionary s_availabilityChangedSubscribers = + new Dictionary(); private static readonly NetworkAvailabilityEventArgs s_availableEventArgs = new NetworkAvailabilityEventArgs(isAvailable: true); private static readonly NetworkAvailabilityEventArgs s_notAvailableEventArgs = new NetworkAvailabilityEventArgs(isAvailable: false); - private static readonly ContextCallback s_runHandlerAvailable = new ContextCallback(RunAvailabilityHandlerAvailable); - private static readonly ContextCallback s_runHandlerNotAvailable = new ContextCallback(RunAvailabilityHandlerNotAvailable); - private static readonly ContextCallback s_runAddressChangedHandler = new ContextCallback(RunAddressChangedHandler); + private static readonly ContextCallback s_runHandlerAvailable = new ContextCallback(RunAvailabilityHandlerAvailable!); + private static readonly ContextCallback s_runHandlerNotAvailable = new ContextCallback(RunAvailabilityHandlerNotAvailable!); + private static readonly ContextCallback s_runAddressChangedHandler = new ContextCallback(RunAddressChangedHandler!); // Introduced for supporting design-time loading of System.Windows.dll [Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)] diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkChangeDelegates.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkChangeDelegates.cs index f5d282a..862252a 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkChangeDelegates.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkChangeDelegates.cs @@ -4,7 +4,7 @@ namespace System.Net.NetworkInformation { - public delegate void NetworkAddressChangedEventHandler(object sender, EventArgs e); + public delegate void NetworkAddressChangedEventHandler(object? sender, EventArgs e); - public delegate void NetworkAvailabilityChangedEventHandler(object sender, NetworkAvailabilityEventArgs e); + public delegate void NetworkAvailabilityChangedEventHandler(object? sender, NetworkAvailabilityEventArgs e); } diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PhysicalAddress.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PhysicalAddress.cs index 5b0f037..4c7581b 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PhysicalAddress.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PhysicalAddress.cs @@ -2,13 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Diagnostics.CodeAnalysis; using System.Text; namespace System.Net.NetworkInformation { public class PhysicalAddress { - private readonly byte[] _address = null; + private readonly byte[] _address; private int _hash = 0; public static readonly PhysicalAddress None = new PhysicalAddress(Array.Empty()); @@ -60,9 +61,9 @@ namespace System.Net.NetworkInformation return _hash; } - public override bool Equals(object comparand) + public override bool Equals(object? comparand) { - PhysicalAddress address = comparand as PhysicalAddress; + PhysicalAddress? address = comparand as PhysicalAddress; if (address == null) { return false; @@ -99,17 +100,17 @@ namespace System.Net.NetworkInformation return (byte[])_address.Clone(); } - public static PhysicalAddress Parse(string address) => address != null ? Parse(address.AsSpan()) : None; + public static PhysicalAddress Parse(string? address) => address != null ? Parse(address.AsSpan()) : None; public static PhysicalAddress Parse(ReadOnlySpan address) { - if (!TryParse(address, out PhysicalAddress value)) + if (!TryParse(address, out PhysicalAddress? value)) throw new FormatException(SR.Format(SR.net_bad_mac_address, new string(address))); return value; } - public static bool TryParse(string address, out PhysicalAddress value) + public static bool TryParse(string? address, [NotNullWhen(true)] out PhysicalAddress? value) { if (address == null) { @@ -120,7 +121,7 @@ namespace System.Net.NetworkInformation return TryParse(address.AsSpan(), out value); } - public static bool TryParse(ReadOnlySpan address, out PhysicalAddress value) + public static bool TryParse(ReadOnlySpan address, [NotNullWhen(true)] out PhysicalAddress? value) { int validSegmentLength; char? delimiter = null; diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Addresses.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Addresses.cs index 01452ee..0228c98 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Addresses.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Addresses.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Collections.Generic; using System.IO; @@ -111,7 +112,7 @@ namespace System.Net.NetworkInformation int afterAddress = fileContents.IndexOf(';', indexOfDhcp); int beforeAddress = fileContents.LastIndexOf(' ', afterAddress); string dhcpAddressString = fileContents.Substring(beforeAddress + 1, afterAddress - beforeAddress - 1); - IPAddress dhcpAddress; + IPAddress? dhcpAddress; if (IPAddress.TryParse(dhcpAddressString, out dhcpAddress)) { collection.Add(dhcpAddress); diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Dns.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Dns.cs index 1afb7327..d5485dd 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Dns.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Dns.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Collections.Generic; using System.IO; @@ -12,9 +13,8 @@ namespace System.Net.NetworkInformation internal static string ParseDnsSuffixFromResolvConfFile(string data) { RowConfigReader rcr = new RowConfigReader(data); - string dnsSuffix; - return rcr.TryGetNextValue("search", out dnsSuffix) ? dnsSuffix : string.Empty; + return rcr.TryGetNextValue("search", out string? dnsSuffix) ? dnsSuffix : string.Empty; } internal static List ParseDnsAddressesFromResolvConfFile(string data) @@ -27,11 +27,9 @@ namespace System.Net.NetworkInformation RowConfigReader rcr = new RowConfigReader(data); List addresses = new List(); - string addressString = null; - while (rcr.TryGetNextValue("nameserver", out addressString)) + while (rcr.TryGetNextValue("nameserver", out string? addressString)) { - IPAddress parsedAddress; - if (IPAddress.TryParse(addressString, out parsedAddress)) + if (IPAddress.TryParse(addressString, out IPAddress? parsedAddress)) { addresses.Add(parsedAddress); } diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Statistics.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Statistics.cs index 8701d55..b8b4382 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Statistics.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Statistics.cs @@ -411,7 +411,7 @@ namespace System.Net.NetworkInformation int index = 0; while (!sr.EndOfStream) { - string line = sr.ReadLine(); + string line = sr.ReadLine()!; if (line.Contains(name)) { string[] pieces = line.Split(new char[] { ' ', ':' }, StringSplitOptions.RemoveEmptyEntries); diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPGlobalProperties.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPGlobalProperties.cs index 9f6a375..f792c6d 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPGlobalProperties.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPGlobalProperties.cs @@ -364,7 +364,7 @@ namespace System.Net.NetworkInformation return new SystemIcmpV6Statistics(); } - public override IAsyncResult BeginGetUnicastAddresses(AsyncCallback callback, object state) + public override IAsyncResult BeginGetUnicastAddresses(AsyncCallback? callback, object? state) { ContextAwareResult asyncResult = new ContextAwareResult(false, false, this, state, callback); asyncResult.StartPostingAsyncOp(false); @@ -385,7 +385,7 @@ namespace System.Net.NetworkInformation throw new ArgumentNullException(nameof(asyncResult)); } - ContextAwareResult result = asyncResult as ContextAwareResult; + ContextAwareResult? result = asyncResult as ContextAwareResult; if (result == null || result.AsyncObject == null || result.AsyncObject.GetType() != typeof(SystemIPGlobalProperties)) { throw new ArgumentException(SR.net_io_invalidasyncresult); @@ -423,7 +423,7 @@ namespace System.Net.NetworkInformation private static void StableUnicastAddressTableCallback(object param) { - EventWaitHandle handle = param as EventWaitHandle; + EventWaitHandle? handle = param as EventWaitHandle; if (handle != null) { handle.Set(); diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPInterfaceProperties.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPInterfaceProperties.cs index cf4b7ef..28bcf2f 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPInterfaceProperties.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPInterfaceProperties.cs @@ -15,14 +15,14 @@ namespace System.Net.NetworkInformation // These are valid for all interfaces. private readonly bool _dnsEnabled = false; private readonly bool _dynamicDnsEnabled = false; - private readonly InternalIPAddressCollection _dnsAddresses = null; - private readonly UnicastIPAddressInformationCollection _unicastAddresses = null; - private readonly MulticastIPAddressInformationCollection _multicastAddresses = null; - private readonly IPAddressInformationCollection _anycastAddresses = null; + private readonly InternalIPAddressCollection _dnsAddresses; + private readonly UnicastIPAddressInformationCollection _unicastAddresses; + private readonly MulticastIPAddressInformationCollection _multicastAddresses; + private readonly IPAddressInformationCollection _anycastAddresses; private readonly Interop.IpHlpApi.AdapterFlags _adapterFlags; private readonly string _dnsSuffix; - private readonly SystemIPv4InterfaceProperties _ipv4Properties; - private readonly SystemIPv6InterfaceProperties _ipv6Properties; + private readonly SystemIPv4InterfaceProperties? _ipv4Properties; + private readonly SystemIPv6InterfaceProperties? _ipv6Properties; private readonly InternalIPAddressCollection _winsServersAddresses; private readonly GatewayIPAddressInformationCollection _gatewayAddresses; private readonly InternalIPAddressCollection _dhcpServers; @@ -80,7 +80,7 @@ namespace System.Net.NetworkInformation throw new NetworkInformationException(SocketError.ProtocolNotSupported); } - return _ipv4Properties; + return _ipv4Properties!; } public override IPv6InterfaceProperties GetIPv6Properties() @@ -90,7 +90,7 @@ namespace System.Net.NetworkInformation throw new NetworkInformationException(SocketError.ProtocolNotSupported); } - return _ipv6Properties; + return _ipv6Properties!; } public override string DnsSuffix diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemNetworkInterface.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemNetworkInterface.cs index 3d3e566..75e0796 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemNetworkInterface.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemNetworkInterface.cs @@ -25,7 +25,7 @@ namespace System.Net.NetworkInformation private readonly uint _index = 0; private readonly uint _ipv6Index = 0; private readonly Interop.IpHlpApi.AdapterFlags _adapterFlags; - private readonly SystemIPInterfaceProperties _interfaceProperties = null; + private readonly SystemIPInterfaceProperties _interfaceProperties; internal static int InternalLoopbackInterfaceIndex { diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemUnicastIPAddressInformation.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemUnicastIPAddressInformation.cs index f1fcfb4..b94a38d 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemUnicastIPAddressInformation.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemUnicastIPAddressInformation.cs @@ -13,7 +13,7 @@ namespace System.Net.NetworkInformation { private readonly long _dhcpLeaseLifetime; private readonly SystemIPAddressInformation _innerInfo; - private readonly IPAddress _ipv4Mask; + private readonly IPAddress? _ipv4Mask; private readonly PrefixOrigin _prefixOrigin; private readonly SuffixOrigin _suffixOrigin; private readonly DuplicateAddressDetectionState _dadState; @@ -54,7 +54,7 @@ namespace System.Net.NetworkInformation return IPAddress.Any; } - return _ipv4Mask; + return _ipv4Mask!; } } diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TeredoHelper.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TeredoHelper.cs index ea6a941..768b3a5 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TeredoHelper.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/TeredoHelper.cs @@ -41,7 +41,7 @@ namespace System.Net.NetworkInformation private readonly Interop.IpHlpApi.StableUnicastIpAddressTableDelegate _onStabilizedDelegate; // Used to cancel notification after receiving the first callback, or when the AppDomain is going down. - private SafeCancelMibChangeNotify _cancelHandle; + private SafeCancelMibChangeNotify? _cancelHandle; private TeredoHelper(Action callback, object state) { @@ -63,7 +63,7 @@ namespace System.Net.NetworkInformation TeredoHelper helper = new TeredoHelper(callback, state); uint err = Interop.IpHlpApi.ERROR_SUCCESS; - SafeFreeMibTable table = null; + SafeFreeMibTable table; lock (s_pendingNotifications) { @@ -105,7 +105,7 @@ namespace System.Net.NetworkInformation return true; } - private void RunCallback(object o) + private void RunCallback(object? o) { if (!_runCallbackCalled) { diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixIPGlobalProperties.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixIPGlobalProperties.cs index 36ce4eb..60d3860 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixIPGlobalProperties.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixIPGlobalProperties.cs @@ -19,7 +19,7 @@ namespace System.Net.NetworkInformation public override NetBiosNodeType NodeType { get { return NetBiosNodeType.Unknown; } } - public override IAsyncResult BeginGetUnicastAddresses(AsyncCallback callback, object state) + public override IAsyncResult BeginGetUnicastAddresses(AsyncCallback? callback, object? state) { Task t = GetUnicastAddressesAsync(); return TaskToApm.Begin(t, callback, state); @@ -32,7 +32,7 @@ namespace System.Net.NetworkInformation public sealed override Task GetUnicastAddressesAsync() { - return Task.Factory.StartNew(s => ((UnixIPGlobalProperties)s).GetUnicastAddresses(), this, + return Task.Factory.StartNew(s => ((UnixIPGlobalProperties)s!).GetUnicastAddresses(), this, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); } diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixIPInterfaceProperties.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixIPInterfaceProperties.cs index 222db47..2d454f7 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixIPInterfaceProperties.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixIPInterfaceProperties.cs @@ -10,11 +10,11 @@ namespace System.Net.NetworkInformation { internal abstract class UnixIPInterfaceProperties : IPInterfaceProperties { - private UnicastIPAddressInformationCollection _unicastAddresses; - private MulticastIPAddressInformationCollection _multicastAddreses; + private UnicastIPAddressInformationCollection? _unicastAddresses; + private MulticastIPAddressInformationCollection? _multicastAddreses; private readonly UnixNetworkInterface _uni; - internal string _dnsSuffix; - internal IPAddressCollection _dnsAddresses; + internal string? _dnsSuffix; + internal IPAddressCollection? _dnsAddresses; public UnixIPInterfaceProperties(UnixNetworkInterface uni, bool globalConfig = false) { @@ -107,7 +107,7 @@ namespace System.Net.NetworkInformation return collection; } - private static string GetDnsSuffix() + private static string? GetDnsSuffix() { try { @@ -119,7 +119,7 @@ namespace System.Net.NetworkInformation } } - private static IPAddressCollection GetDnsAddresses() + private static IPAddressCollection? GetDnsAddresses() { try { diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixNetworkInterface.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixNetworkInterface.cs index 0ace05e..2e10477 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixNetworkInterface.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixNetworkInterface.cs @@ -14,7 +14,7 @@ namespace System.Net.NetworkInformation protected NetworkInterfaceType _networkInterfaceType = NetworkInterfaceType.Unknown; internal PhysicalAddress _physicalAddress = PhysicalAddress.None; internal List _unicastAddresses = new List(); - internal List _multicastAddresses; + internal List? _multicastAddresses; // If this is an ipv6 device, contains the Scope ID. protected uint? _ipv6ScopeId = null; @@ -63,7 +63,7 @@ namespace System.Net.NetworkInformation /// /// Returns a list of all Unicast addresses of the interface's IP Addresses. /// - public List MulticastAddresess { get { return _multicastAddresses; } } + public List? MulticastAddresess { get { return _multicastAddresses; } } // Adds any IPAddress to this interface's List of addresses. protected void AddAddress(IPAddress ipAddress, int prefix) -- 2.7.4