Esempio n. 1
0
 /// <summary>Compares two phones for equality, member-by-member.</summary>
 public bool MemberwiseEquals(PhoneStruct other) {
    if (Object.ReferenceEquals(this, other)) return true;
    if (other == null) return false;
    if (IsCustom != other.IsCustom) return false;
    if (CountryCode != other.CountryCode) return false;
    if (AreaCode != other.AreaCode) return false;
    if (LocalNumber != other.LocalNumber) return false;
    if (Extension != other.Extension) return false;
    if (DisplayNumber != other.DisplayNumber) return false;
    if (Number != other.Number) return false;
    return true;
 }
Esempio n. 2
0
      /// <summary>Parses a phone structure from string representation.</summary>
      /// <param name="number">The phone number to parse.</param>
      /// <returns>The parsed phone number</returns>
      public static PhoneStruct Parse(string number) {
         if (number.IsEmpty()) return null;

         var phone = new PhoneStruct {
            Number = number,
            IsCustom = true
         };
         Match match = null;
         for (var i = 0; i < _rePhoneFormats.Length; i++) {
            match = _rePhoneFormats[i].Match(number);
            if (match.Success) break;
         }
         if (match != null && match.Success) {
            var parts = match.Groups;
            switch (parts.Count) {
               case 2:
                  phone.LocalNumber = parts[1].Value;
                  phone.Number = phone.LocalNumber;
                  break;
               case 3:
                  phone.AreaCode = parts[1].Value;
                  phone.LocalNumber = parts[2].Value;
                  phone.Number = phone.AreaCode + phone.LocalNumber;
                  break;
               case 4:
                  phone.CountryCode = Int32.Parse(parts[1].Value);
                  phone.AreaCode = parts[2].Value;
                  phone.LocalNumber = parts[3].Value;
                  phone.DisplayNumber = "+{0} {1}-{2}".Substitute(phone.CountryCode, phone.AreaCode, phone.LocalNumber);
                  phone.Number = "+" + phone.CountryCode + phone.AreaCode + phone.LocalNumber;
                  phone.IsCustom = false;
                  break;
            }
            if (phone.LocalNumber.NotEmpty()) {
               phone.LocalNumber = phone.LocalNumber.RemoveAll(_reWhitespace);
            }
            if (phone.Number.NotEmpty()) {
               phone.Number = phone.Number.RemoveAll(_reWhitespace);
            }
         }
         return phone;
      }
Esempio n. 3
0
 /// <summary>Converts an <see cref="PhoneStruct"/> object to an <see cref="Phone"/> primitive.</summary>
 public static Phone ToPhone(PhoneStruct phone) {
    return new Phone(phone);
 }