Class Telefon
Representerar ett telefonnummer.
Inherited Members
Namespace: IRM.Domain
Assembly: IRM.dll
Syntax
public class Telefon : ValueObject
Constructors
Telefon(Int16, String)
Initializes a new instance of the Telefon class.
Declaration
public Telefon(short landsnummer, string nummer)
Parameters
System.Int16
landsnummer
Landskoden som behöver slås när man inte befinner sig i landet i fråga. |
String
nummer
Hela numret inkl riktnummer, men utan |
Telefon(String, String)
Initializes a new instance of the Telefon class.
Declaration
public Telefon(string landsnummer, string nummer)
Parameters
String
landsnummer
Landskoden som behöver slås när man inte befinner sig i landet i fråga. |
String
nummer
Hela numret inkl riktnummer, men utan |
Properties
Abonnentnummer
Lokala abonnentnumret för svenska nummer, dvs Nummer utan Riktnummer. För internationella nummer returneras null;
Declaration
public string Abonnentnummer { get; }
Property Value
String
|
Empty
Provides a value to use when there is no phone data.
Declaration
public static Telefon Empty { get; }
Property Value
Telefon
|
IsEmpty
Gets if this instance has a value or not.
Declaration
public bool IsEmpty { get; }
Property Value
Boolean
|
Landsnummer
Landskoden som behöver slås när man inte befinner sig i landet i fråga.
Declaration
public short? Landsnummer { get; }
Property Value
System.Nullable<System.Int16>
|
NationelltNummer
Gets if the phone number is a national (swedish) phone number or not.
Declaration
public bool NationelltNummer { get; }
Property Value
Boolean
|
Nummer
Hela numret inkl riktnummer, men utan Landsnummer.
Declaration
public string Nummer { get; }
Property Value
String
|
Riktnummer
Riktnummer delen av Nummer för svenska nummer. För internationella nummer returneras null;
Declaration
public string Riktnummer { get; }
Property Value
String
|
RiktnummerOmråde
För Geografiskt nummer får man en beskrivande text (ortsnamn) för Riktnummer.
Declaration
public string RiktnummerOmråde { get; }
Property Value
String
|
Typ
Beskriver vilken typ av telefonnummer.
Declaration
public TelefonnummerTyp Typ { get; }
Property Value
TelefonnummerTyp
|
Methods
Equals(ValueObject)
Compares two Value Objects according to atomic values returned by GetAtomicValues().
Declaration
public override bool Equals(ValueObject obj)
Parameters
ValueObject
obj
ValueObject to compare to. |
Returns
Boolean
true if objects are considered equal; otherwise false. |
Overrides
GetAtomicValues()
To be overridden in inheriting clesses for providing a collection of atomic values of this Value Object.
Declaration
protected override IEnumerable<object> GetAtomicValues()
Returns
IEnumerable<Object>
Collection of atomic values. |
Overrides
Parse(String, String)
Konverterar en sträng med ett telefonnummer till motsvarande Telefon objekt.
Declaration
public static Telefon Parse(string nummer, string defaultLandkod = "SE")
Parameters
String
nummer
En sträng med telefonnumret. |
String
defaultLandkod
Landkoden (ISO) för det landsnummer som ska användas om |
Returns
Telefon
|
Exceptions
ArgumentOutOfRangeException
Landkoden är inte en korrekt ISO landskod. |
System.FormatException
Det gick inte att tolka landsnumret eller landsnumret är felaktigt. |
Replace(Telefon)
Replaces the values with the values from the supplied Telefon. This method only exists to work around a limitation of owned entites in EF Core 2.0 and will be removed as soon as possible.
Declaration
public void Replace(Telefon telefon)
Parameters
Telefon
telefon
The new Telefon values to use. |
ToString()
Converts the phone value of this instance to its equivalent string representation.
Declaration
public override string ToString()
Returns
String
The phone number of this instance |
Overrides
ToString(String)
Converts the phone value of this instance to its equivalent string representation, using the specified format.
Declaration
public string ToString(string format)
Parameters
String
format
A standard or custom phone format string. |
Returns
String
The phone number of this instance as specified by |
Remarks
The format parameter can be any valid standard phone format specifier, as well as some combination of custom phone format specifiers. If format is null or an empty string (""), the return value of this instance is formatted with the general phone format specifier ("G").
The standard phone format specifiers which is lower case are more compact, than the upper case counter parts.
Format specifier | Description | Examples |
---|---|---|
"G" or "F" | The complete phone number with Landsnummer, Riktnummer and Abonnentnummer fully formated with spaces even in Abonnentnummer. | +46 8-585 011 29 |
"f" | The complete phone number with Landsnummer, Riktnummer and Abonnentnummer. | +46 8-58501129 |
"N" | The phone number with Riktnummer and Abonnentnummer fully formated with spaces even in Abonnentnummer. | 08-585 011 29 |
"n" | The phone number with Riktnummer and Abonnentnummer. | 08-58501129 |
"S" | The phone number with Riktnummer and Abonnentnummer formated with only spaces, even in Abonnentnummer. | 08 585 011 29 |
"s" | The phone number with Riktnummer and Abonnentnummer formated with only spaces. | 08 58501129 |
"I" | The phone number formated according to ITU-T E.123 with Landsnummer, Riktnummer and Abonnentnummer. | +46 (8) 5850 1129 |
"i" | The phone number formated according to ITU-T E.123 with Riktnummer and Abonnentnummer. | (08) 5850 1129 |
You can create a custom phone format string, which consists of one or more custom phone specifiers, to define how to format phone data. The following table describes the custom phone format specifiers.
Format specifier | Description | Examples |
---|---|---|
"c" | Placeholder for the country code. | +46858501129 ("00c") -> 0046 |
"a" | Placeholder for the area code. | +46858501129 ("a") -> 08 |
"l" | Placeholder for the local number. | +46858501129 ("l") -> 58501129, +46858501129 ("l l") -> 5850 1129, +46858501129 ("l l l") -> 585 011 29 |
We expect the custom format specifiers to come in the following order: c, a, l. If they don't the result can be unexpected. It is not possible to add custom charachters between the l specifiers.
TryParse(String, out Telefon)
Konverterar en sträng med ett telefonnummer till motsvarande Telefon objekt. Ett returvärde indikerar om konverteringen gick bra eller inte.
Declaration
public static bool TryParse(string nummer, out Telefon result)
Parameters
String
nummer
En sträng med telefonnumret. |
Telefon
result
När metoden returnerar innehåller den Telefon för numret i |
Returns
Boolean
true om |
Remarks
Använder Sverige (SE) som landkod.
TryParse(String, String, out Telefon)
Konverterar en sträng med ett telefonnummer till motsvarande Telefon objekt. Ett returvärde indikerar om konverteringen gick bra eller inte.
Declaration
public static bool TryParse(string nummer, string defaultLandkod, out Telefon result)
Parameters
String
nummer
En sträng med telefonnumret. |
String
defaultLandkod
Landkoden (ISO) för det landsnummer som ska användas om |
Telefon
result
När metoden returnerar innehåller den Telefon för numret i |
Returns
Boolean
true om |