This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CpfCnpjUtils { | |
private static final int[] pesoCPF = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2}; | |
private static final int[] pesoCNPJ = {6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2}; | |
public static boolean isValid(String cpfCnpj) { | |
return (isValidCPF(cpfCnpj) || isValidCNPJ(cpfCnpj)); | |
} | |
private static int calcularDigito(String str, int[] peso) { | |
int soma = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace CpfCnpj | |
{ | |
public static class CpfCnpjUtils | |
{ | |
public static bool IsValid(string cpfCnpj) | |
{ | |
return (IsCpf(cpfCnpj) || IsCnpj(cpfCnpj)); | |
} | |
private static bool IsCpf(string cpf) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static T GetEnumValue<T>(this string description) | |
{ | |
var type = typeof(T); | |
if (!type.GetTypeInfo().IsEnum) | |
throw new ArgumentException(); | |
var field = type.GetFields().SelectMany(f => f.GetCustomAttributes(typeof(DescriptionAttribute), false), (f, a) => new { Field = f, Att = a }) | |
.Where(a => ((DescriptionAttribute)a.Att).Description == description).SingleOrDefault(); | |
return field == null ? default(T) : (T)field.Field.GetRawConstantValue(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string GetDescription(this Enum enumerationValue) | |
{ | |
Type type = enumerationValue.GetType(); | |
MemberInfo member = type.GetMembers().Where(w => w.Name == Enum.GetName(type, enumerationValue)).FirstOrDefault(); | |
var attribute = member?.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault() as DescriptionAttribute; | |
return attribute?.Description != null ? attribute.Description : enumerationValue.ToString(); | |
} |