/// <summary> /// Validate whether a CPF is valid or not /// </summary> /// <param name="cpf">xxx.xxx.xxx-xx or xxxxxxxxxxx</param> /// <typeparam name="string"></typeparam> /// <returns>true or false</returns> public static bool IsCPFValid(this string cpf) { cpf = CharacterChanges.RemovePointsDashesBarsAndSpaces(cpf); if (cpf.Length != 11) { return(false); } var isNumberOnly = long.TryParse(cpf, out _); if (!isNumberOnly) { return(false); } if (CpfListWithRepeatedNumbers().Contains(cpf)) { return(false); } var cpfWithoutDigit = cpf.Substring(0, 9); int[] multiplierNumbers01 = { 10, 9, 8, 7, 6, 5, 4, 3, 2 }; int[] multiplierNumbers02 = { 11, 10, 9, 8, 7, 6, 5, 4, 3, 2 }; var sum01 = 0; for (int i = 0; i < 9; i++) { sum01 += int.Parse(cpfWithoutDigit[i].ToString()) * multiplierNumbers01[i]; } var restfDivision01 = sum01 % 11; var firstCheckDigit = restfDivision01 < 2 ? 0 : 11 - restfDivision01; cpfWithoutDigit += firstCheckDigit; var sum02 = 0; for (int i = 0; i < 10; i++) { sum02 += int.Parse(cpfWithoutDigit[i].ToString()) * multiplierNumbers02[i]; } var restfDivision02 = sum02 % 11; var secondDigitChecker = restfDivision02 < 2 ? 0 : 11 - restfDivision02; var verifyingDigit = $"{firstCheckDigit}{secondDigitChecker}"; return(cpf.EndsWith(verifyingDigit)); }
public override int GetHashCode() { int hash = 1; hash ^= newPlayerNames_.GetHashCode(); hash ^= CharacterChanges.GetHashCode(); hash ^= tileItemChanges_.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
/// <summary> /// Validate whether a CNPJ is valid or not /// </summary> /// <param name="cnpj">xx.xxx.xxx/xxxx-xx or xxxxxxxxxxxxxx</param> /// <typeparam name="string"></typeparam> /// <returns>true or false</returns> public static bool IsCNPJValid(this string cnpj) { cnpj = CharacterChanges.RemovePointsDashesBarsAndSpaces(cnpj); if (cnpj.Length != 14) { return(false); } var isNumberOnly = long.TryParse(cnpj, out _); if (!isNumberOnly) { return(false); } if (CnpjListWithRepeatedNumbers().Contains(cnpj)) { return(false); } var cnpjWithoutDigit = cnpj.Substring(0, 12); int[] multiplierNumbers01 = { 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 }; int[] multiplierNumbers02 = { 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 }; var sum01 = 0; for (int i = 0; i < multiplierNumbers01.Length; i += 1) { sum01 += ToInt32(cnpjWithoutDigit[i].ToString()) * multiplierNumbers01[i]; } var restfDivision01 = sum01 % 11; var firstCheckDigit = restfDivision01 < 2 ? 0 : 11 - restfDivision01; cnpjWithoutDigit += firstCheckDigit; var sum02 = 0; for (int i = 0; i < multiplierNumbers02.Length; i += 1) { sum02 += ToInt32(cnpjWithoutDigit[i].ToString()) * multiplierNumbers02[i]; } var restfDivision02 = sum02 % 11; var secondDigitChecker = restfDivision02 < 2 ? 0 : 11 - restfDivision02; var verifyingDigit = $"{firstCheckDigit}{secondDigitChecker}"; return(cnpj.EndsWith(verifyingDigit)); }
public bool Equals(GameChange other) { if (ReferenceEquals(other, null)) { return(false); } if (ReferenceEquals(other, this)) { return(true); } if (!newPlayerNames_.Equals(other.newPlayerNames_)) { return(false); } if (!CharacterChanges.Equals(other.CharacterChanges)) { return(false); } if (!tileItemChanges_.Equals(other.tileItemChanges_)) { return(false); } return(Equals(_unknownFields, other._unknownFields)); }