From eed06a29ad2c258c69e04efa9ffe9977db569ed8 Mon Sep 17 00:00:00 2001 From: Trevor Pilley Date: Thu, 24 Oct 2024 07:52:01 +0000 Subject: [PATCH] C#12 Primary Constructors --- src/PhoneNumbers/Parsers/PhoneNumberParser.cs | 14 ++++---------- src/PhoneNumbers/PhoneNumber.cs | 12 +++--------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/PhoneNumbers/Parsers/PhoneNumberParser.cs b/src/PhoneNumbers/Parsers/PhoneNumberParser.cs index 86d43b7a5..0d1c24878 100644 --- a/src/PhoneNumbers/Parsers/PhoneNumberParser.cs +++ b/src/PhoneNumbers/Parsers/PhoneNumberParser.cs @@ -3,20 +3,14 @@ namespace PhoneNumbers.Parsers; /// /// The base class for a class which parses a string containing a phone number into a instance. /// -internal abstract class PhoneNumberParser +/// The of the country for the parser. +/// Thrown if is null. +internal abstract class PhoneNumberParser(CountryInfo countryInfo) { - /// - /// Initialises a new instance of the class. - /// - /// The of the country for the parser. - /// Thrown if is null. - protected PhoneNumberParser(CountryInfo countryInfo) => - Country = countryInfo ?? throw new ArgumentNullException(nameof(countryInfo)); - /// /// Gets the for the parser. /// - protected CountryInfo Country { get; } + protected CountryInfo Country { get; } = countryInfo ?? throw new ArgumentNullException(nameof(countryInfo)); /// /// Parses the phone number represented in the specified string into a instance. diff --git a/src/PhoneNumbers/PhoneNumber.cs b/src/PhoneNumbers/PhoneNumber.cs index 54ac1ee37..d3511d0eb 100644 --- a/src/PhoneNumbers/PhoneNumber.cs +++ b/src/PhoneNumbers/PhoneNumber.cs @@ -6,15 +6,9 @@ namespace PhoneNumbers; /// /// The base class representing a . /// -public abstract class PhoneNumber +/// The for the phone number. +public abstract class PhoneNumber(PhoneNumberHint phoneNumberHint) { - /// - /// Initialises a new instance of the class. - /// - /// The for the phone number. - protected PhoneNumber(PhoneNumberHint phoneNumberHint) => - Hint = phoneNumberHint; - /// /// Gets the for the phone number. /// @@ -52,7 +46,7 @@ protected PhoneNumber(PhoneNumberHint phoneNumberHint) => /// /// Gets the . /// - protected PhoneNumberHint Hint { get; } + protected PhoneNumberHint Hint { get; } = phoneNumberHint; /// /// Parses the specified phone number value into a instance based upon its calling code using the default .