@@ -78,11 +78,12 @@ public abstract record IpAddr : ISpanFormattable, ISpanParsable<IpAddr>
78
78
public static bool TryParse ([NotNullWhen (true )] string ? s , IFormatProvider ? provider , [MaybeNullWhen (false )] out IpAddr result );
79
79
80
80
public static int Count { get ; } => 3 ;
81
- public static string ? GetName (IpAddr t );
81
+ public static string ? GetName (IpAddr ipaddr );
82
82
public static string [] GetNames () => [nameof (V4 ), nameof (V6 ), nameof (None )];
83
- public static byte GetNumericValue (IpAddr t );
84
- public static IpAddrVariant ConvertEnum (IpAddr t );
85
- public static bool TryConvertEnum ([NotNullWhen (true )] IpAddr ? t , [MaybeNullWhen (false )] out IpAddrVariant result );
83
+ public static ReadOnlySpan <byte > GetUtf8Name (IpAddr ipaddr );
84
+ public static byte GetNumericValue (IpAddr ipaddr );
85
+ public static IpAddrVariant ConvertEnum (IpAddr ipaddr );
86
+ public static bool TryConvertEnum ([NotNullWhen (true )] IpAddr ? ipaddr , [MaybeNullWhen (false )] out IpAddrVariant result );
86
87
public static IpAddr Parse (ReadOnlySpan <char > s , bool ignoreCase , IFormatProvider ? provider = default );
87
88
public static bool TryParse (ReadOnlySpan <char > s , out IpAddr result );
88
89
public static bool TryParse (ReadOnlySpan <char > s , bool ignoreCase , IFormatProvider ? provider , [MaybeNullWhen (false )] out IpAddr result );
@@ -94,7 +95,6 @@ public abstract record IpAddr : ISpanFormattable, ISpanParsable<IpAddr>
94
95
<details ><summary >Generated All Code (IpAddr .g .cs )< / summary >
95
96
96
97
```csharp
97
-
98
98
// <auto-generated> This .cs file is generated by VariantEnum. </auto-generated>
99
99
#nullable enable
100
100
#pragma warning disable CS0219 // The variable 'variable' is assigned but its value is never used
@@ -268,6 +268,18 @@ public abstract record IpAddr :
268
268
[MethodImpl (MethodImplOptions .AggressiveInlining )]
269
269
public static string [] GetNames () => [nameof (V4 ), nameof (V6 ), nameof (None )];
270
270
271
+ [MethodImpl (MethodImplOptions .AggressiveInlining )]
272
+ public static ReadOnlySpan <byte > GetUtf8Name (IpAddr ipaddr )
273
+ {
274
+ return ipaddr switch
275
+ {
276
+ V4 => " V4" u8 ,
277
+ V6 => " V6" u8 ,
278
+ None => " None" u8 ,
279
+ _ => []
280
+ };
281
+ }
282
+
271
283
[MethodImpl (MethodImplOptions .AggressiveInlining )]
272
284
public static byte GetNumericValue (IpAddr ipaddr )
273
285
{
@@ -351,7 +363,7 @@ public abstract record IpAddr :
351
363
[MethodImpl (MethodImplOptions .AggressiveInlining )]
352
364
public static bool TryParse (ReadOnlySpan <char > s , IFormatProvider ? provider , [MaybeNullWhen (false )] out IpAddr result )
353
365
{
354
- return TryParse (s , false , null , out result );
366
+ return TryParse (s , false , provider , out result );
355
367
}
356
368
357
369
public static bool TryParse (ReadOnlySpan <char > s , bool ignoreCase , IFormatProvider ? provider , [MaybeNullWhen (false )] out IpAddr result )
@@ -495,6 +507,13 @@ foreach (var name in names)
495
507
// None
496
508
```
497
509
510
+ ### GetUtf8Name
511
+
512
+ ```csharp
513
+ var utf8Name = IpAddr .GetUtf8Name (new IpAddr .V4 (127 , 0 , 0 , 1 ));
514
+ Console .WriteLine (Encoding .UTF8 .GetString (utf8Name )); // V4
515
+ ```
516
+
498
517
### IsDefined
499
518
500
519
```csharp
0 commit comments