Skip to content

Commit 2b6c59b

Browse files
authored
IPInterfaceProperties.GetIPv(4|6)Properties never returns null (#11056)
The null checking in the code samples is unnecessary and misleading so I'm proposing to delete it. Moreover, we should call out in the remarks section the necessity of a capability check so users avoid walking into an exception in case of missing protocol support.
1 parent e360952 commit 2b6c59b

File tree

4 files changed

+5
-18
lines changed

4 files changed

+5
-18
lines changed

snippets/cpp/VS_Snippets_Remoting/NCLNetInfo2/CPP/networkexamples.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,11 +836,6 @@ void DisplayIPv4NetworkInterfaces()
836836

837837
// Try to get the IPv4 interface properties.
838838
IPv4InterfaceProperties ^ p = adapterProperties->GetIPv4Properties();
839-
if ( !p )
840-
{
841-
Console::WriteLine( "No IPv4 information is available for this interface." );
842-
continue;
843-
}
844839

845840
// Display the IPv4 specific data.
846841
Console::WriteLine( " Index ............................. : {0}",

snippets/csharp/System.Net.NetworkInformation/DuplicateAddressDetectionState/Overview/networkexamples.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -796,12 +796,6 @@ public static void DisplayIPv4NetworkInterfaces()
796796
// Try to get the IPv4 interface properties.
797797
IPv4InterfaceProperties p = adapterProperties.GetIPv4Properties();
798798

799-
if (p == null)
800-
{
801-
Console.WriteLine("No IPv4 information is available for this interface.");
802-
Console.WriteLine();
803-
continue;
804-
}
805799
// Display the IPv4 specific data.
806800
Console.WriteLine(" Index ............................. : {0}", p.Index);
807801
Console.WriteLine(" MTU ............................... : {0}", p.Mtu);

snippets/visualbasic/VS_Snippets_Remoting/NCLNetInfo2/VB/networkexamples.vb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,7 @@ Public Class NetworkingExample
695695
Dim adapterProperties As IPInterfaceProperties = adapter.GetIPProperties()
696696
' Try to get the IPv4 interface properties.
697697
Dim p As IPv4InterfaceProperties = adapterProperties.GetIPv4Properties()
698-
699-
If p Is Nothing Then
700-
Console.WriteLine("No IPv4 information is available for this interface.")
701-
GoTo ContinueForEach1
702-
End If
698+
703699
' Display the IPv4 specific data.
704700
Console.WriteLine(" Index ............................. : {0}", p.Index)
705701
Console.WriteLine(" MTU ............................... : {0}", p.Mtu)

xml/System.Net.NetworkInformation/IPInterfaceProperties.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,8 @@
494494
495495
## Remarks
496496
For a detailed description of the information available for an interface that supports IPv4, see the <xref:System.Net.NetworkInformation.IPv4InterfaceProperties> class documentation. Note that the object returned by the <xref:System.Net.NetworkInformation.IPInterfaceProperties.GetIPv4Properties%2A> method reflects the configuration as of the time the object is created. This information is not updated dynamically.
497-
497+
A <xref:System.Net.NetworkInformation.NetworkInformationException> is thrown if the interface does not support the IPv4 protocol, therefore it's recommended to check IPv4 support calling <xref:System.Net.NetworkInformation.NetworkInterface.Supports%2A> on the originating <xref:System.Net.NetworkInformation.NetworkInterface> instance before querying the IPv4 properties.
498+
498499
]]></format>
499500
</remarks>
500501
<exception cref="T:System.Net.NetworkInformation.NetworkInformationException">The interface does not support the IPv4 protocol.</exception>
@@ -544,7 +545,8 @@
544545
545546
## Remarks
546547
For a detailed description of the information available for an interface that supports IPv6, see the <xref:System.Net.NetworkInformation.IPv6InterfaceProperties> documentation. Note that the object returned by the <xref:System.Net.NetworkInformation.IPInterfaceProperties.GetIPv6Properties%2A> method reflects the configuration as of the time the object is created. This information is not updated dynamically.
547-
548+
A <xref:System.Net.NetworkInformation.NetworkInformationException> is thrown if the interface does not support the IPv6 protocol, therefore it's recommended to check IPv6 support calling <xref:System.Net.NetworkInformation.NetworkInterface.Supports%2A> on the originating <xref:System.Net.NetworkInformation.NetworkInterface> instance before querying the IPv6 properties.
549+
548550
]]></format>
549551
</remarks>
550552
<exception cref="T:System.Net.NetworkInformation.NetworkInformationException">The interface does not support the IPv6 protocol.</exception>

0 commit comments

Comments
 (0)