Skip to content

Instantly share code, notes, and snippets.

Romulo AC rdakar

Block or report user

Report or block rdakar

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rdakar
rdakar / Validação de CPF e CNPJ - Java
Created Sep 18, 2017
Validação de CPF e CNPJ - Java
View Validação de CPF e CNPJ - Java
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;
@rdakar
rdakar / Validação de CPF e CNPJ - C#
Created Aug 14, 2017
Validação de CPF e CNPJ - C#
View Validação de CPF e CNPJ - C#
namespace CpfCnpj
{
public static class CpfCnpjUtils
{
public static bool IsValid(string cpfCnpj)
{
return (IsCpf(cpfCnpj) || IsCnpj(cpfCnpj));
}
private static bool IsCpf(string cpf)
@rdakar
rdakar / EnumExtender.GetEnumValue
Created Jul 2, 2017
EnumExtender.GetEnumValue
View EnumExtender.GetEnumValue
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();
}
@rdakar
rdakar / EnumExtender.GetDescription
Created Jun 27, 2017
EnumExtender.GetDescription
View EnumExtender.GetDescription
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();
}
You can’t perform that action at this time.