-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Netin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Background and motivation
Cheaper IPAddress.TryParse(span, out _) for when you don't need the result.
API Proposal
namespace System.Net;
public partial class IPAddress
{
public static IPAddress Parse(string ipString);
public static IPAddress Parse(ReadOnlySpan<char> ipSpan);
public static IPAddress Parse(ReadOnlySpan<byte> utf8Text);
public static bool TryParse(string? ipString, out IPAddress? address);
public static bool TryParse(ReadOnlySpan<char> ipSpan, out IPAddress? address);
public static bool TryParse(ReadOnlySpan<byte> utf8Text, out IPAddress? result);
+ public static bool IsValid(ReadOnlySpan<char> ipSpan);
+ public static bool IsValid(ReadOnlySpan<byte> utf8Text);
}API Usage
-if (IPAddress.TryParse(text, out _))
+if (IPAddress.IsValid(text))We have an internal helper TargetHostNameHelper.IsValidAddress that appears to be doing exactly what IPAddress.IsValid would be:
| internal static unsafe bool IsValidAddress(string? hostname) |
Alternative Designs
- Allow specifying IPv4 or IPv6 only?
Risks
No response
stephentoub, HighPerfDotNet, antonfirsov, colejohnson66, KeterSCP and 4 more
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Netin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged