Skip to content

Commit

Permalink
C#12 Primary Constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
TrevorPilley committed Oct 24, 2024
1 parent 8429c9b commit 3792d22
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
14 changes: 4 additions & 10 deletions src/PhoneNumbers/Parsers/PhoneNumberParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@ namespace PhoneNumbers.Parsers;
/// <summary>
/// The base class for a class which parses a string containing a phone number into a <see cref="PhoneNumber"/> instance.
/// </summary>
internal abstract class PhoneNumberParser
/// <param name="countryInfo">The <see cref="CountryInfo"/> of the country for the parser.</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="countryInfo"/> is null.</exception>
internal abstract class PhoneNumberParser(CountryInfo countryInfo)
{
/// <summary>
/// Initialises a new instance of the <see cref="PhoneNumberParser"/> class.
/// </summary>
/// <param name="countryInfo">The <see cref="CountryInfo"/> of the country for the parser.</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="countryInfo"/> is null.</exception>
protected PhoneNumberParser(CountryInfo countryInfo) =>
Country = countryInfo ?? throw new ArgumentNullException(nameof(countryInfo));

/// <summary>
/// Gets the <see cref="CountryInfo"/> for the parser.
/// </summary>
protected CountryInfo Country { get; }
protected CountryInfo Country { get; } = countryInfo ?? throw new ArgumentNullException(nameof(countryInfo));

/// <summary>
/// Parses the phone number represented in the specified string into a <see cref="PhoneNumber"/> instance.
Expand Down
12 changes: 3 additions & 9 deletions src/PhoneNumbers/PhoneNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ namespace PhoneNumbers;
/// <summary>
/// The base class representing a <see cref="PhoneNumber"/>.
/// </summary>
public abstract class PhoneNumber
/// <param name="phoneNumberHint">The <see cref="PhoneNumberHint"/> for the phone number.</param>
public abstract class PhoneNumber(PhoneNumberHint phoneNumberHint)
{
/// <summary>
/// Initialises a new instance of the <see cref="PhoneNumber"/> class.
/// </summary>
/// <param name="phoneNumberHint">The <see cref="PhoneNumberHint"/> for the phone number.</param>
protected PhoneNumber(PhoneNumberHint phoneNumberHint) =>
Hint = phoneNumberHint;

/// <summary>
/// Gets the <see cref="CountryInfo"/> for the phone number.
/// </summary>
Expand Down Expand Up @@ -52,7 +46,7 @@ protected PhoneNumber(PhoneNumberHint phoneNumberHint) =>
/// <summary>
/// Gets the <see cref="PhoneNumberHint"/>.
/// </summary>
protected PhoneNumberHint Hint { get; }
protected PhoneNumberHint Hint { get; } = phoneNumberHint;

/// <summary>
/// Parses the specified phone number value into a <see cref="PhoneNumber"/> instance based upon its calling code using the default <see cref="ParseOptions"/>.
Expand Down

0 comments on commit 3792d22

Please sign in to comment.