/// <summary> /// Validates the specified cellphone number. /// </summary> /// <param name="cellphoneNumber">The cellphone number.</param> /// <param name="omitNationCode">if set to <c>true</c> [omit nation code].</param> public void Validate(CellphoneNumber cellphoneNumber, bool omitNationCode = false) { try { cellphoneNumber.CheckNullObject(nameof(cellphoneNumber)); if (!omitNationCode && !cellphoneNumber.NationCode.MeaningfulEquals(NationCode)) { throw ExceptionFactory.CreateInvalidObjectException(nameof(cellphoneNumber.NationCode), new { expected = NationCode, actual = cellphoneNumber.NationCode }); } var regex = GetRegex(); regex.CheckNullObject(nameof(regex)); cellphoneNumber.Number.CheckEmptyString(nameof(cellphoneNumber.Number)); if (!regex.IsMatch(cellphoneNumber.Number)) { throw ExceptionFactory.CreateInvalidObjectException(nameof(cellphoneNumber.Number), new { cellphoneNumber }); } } catch (Exception ex) { throw ex.Handle(new { cellphoneNumber, omitNationCode }); } }
/// <summary> /// Checks the empty cellphone number. /// </summary> /// <param name="cellphoneNumber">The cellphone number.</param> /// <param name="objectIdentity">The object identity.</param> /// <param name="friendlyHint">The friendly hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <exception cref="NullObjectException"></exception> /// <exception cref="ExceptionScene"></exception> public static void CheckEmptyCellphoneNumber(this CellphoneNumber cellphoneNumber, string objectIdentity = null, FriendlyHint friendlyHint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { if (cellphoneNumber == null || string.IsNullOrWhiteSpace(cellphoneNumber.Number)) { throw new NullObjectException(objectIdentity.SafeToString(nameof(cellphoneNumber)), friendlyHint, new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName }); } }
/// <summary> /// Objects to cellphone number. /// </summary> /// <param name="data">The data.</param> /// <returns></returns> public static CellphoneNumber ObjectToCellphoneNumber(this object data) { return(CellphoneNumber.FromString(ObjectToString(data))); }
/// <summary> /// Reads the JSON representation of the object. /// </summary> /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param> /// <param name="objectType">Type of the object.</param> /// <param name="existingValue">The existing value of object being read.</param> /// <param name="serializer">The calling serializer.</param> /// <returns> /// The object value. /// </returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { return(reader.Value == null ? null : CellphoneNumber.FromString(reader.Value.ToString())); }