Namespace PhoneNumbers.Extensions
Classes
- PhoneNumberAttribute
Validates that a property, field, or parameter is a valid phone number, using the same validity check as IsValidNumber(PhoneNumber) rather than a loose format regex. Accepts a string (parsed via Region) or an already-parsed PhoneNumber.
- PhoneNumberExtensions
C#-idiomatic extension methods over PhoneNumber for the formatting and validity checks callers reach for most often, so they read as
number.ToE164()/number.IsValid()instead ofPhoneNumberUtil.GetInstance().Format(number, PhoneNumberFormat.E164).
- PhoneNumberJsonContext
Source-generated JsonSerializerContext for PhoneNumber, so consumers building trimmed or Native AOT apps do not need to hand-write one.
- PhoneNumberJsonOptions
Ready-made JsonSerializerOptions for serializing PhoneNumber under Native AOT / trimming, where the reflection-based default resolver is unavailable. Combines PhoneNumberJsonContext (source-generated type metadata) with PhoneNumberConverter (the actual read/write logic) so callers cannot wire the two together incorrectly — see the remarks on PhoneNumberJsonContext for why doing it by hand is easy to get wrong.
- PhoneNumberTypeConverter
Converts a PhoneNumber to and from its E.164 string representation. Not applied automatically — register it where needed, e.g.
TypeDescriptor.AddAttributes(typeof(PhoneNumbers.PhoneNumber), new TypeConverterAttribute(typeof(PhoneNumberTypeConverter)));