Skip to content

Instantly share code, notes, and snippets.

View flpinheiro's full-sized avatar
💭
Working with .net 6, react, and studying.net Maui

Felipe Luís Pinheiro flpinheiro

💭
Working with .net 6, react, and studying.net Maui
View GitHub Profile
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
namespace Extensions;
public static class StringExtensions
{
public static string FirstCharToUpper(this string input) =>
input switch
@flpinheiro
flpinheiro / ObjectExtensions.cs
Last active September 27, 2022 02:40
9bject extension to create dictionary from object and vice versa
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
public static class ObjectExtensions
{
public static T ToObject<T>(this IDictionary<string, object> source)
where T : class, new()
{
var someObject = new T();
[AttributeUsage(AttributeTargets.Property)]
public class DateLimitValidationAttribute : RequiredAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
base.IsValid(value, validationContext);
if (value == null) return ValidationResult.Success;
var date = Convert.ToDateTime(value);
public sealed class DateOnlyJsonConverter : JsonConverter<DateOnly>
{
public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return DateOnly.FromDateTime(reader.GetDateTime());
}
public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
{
var isoDate = value.ToString("O");
public static class ExcelExtensions
{
public const string ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
/// <summary>
/// Creates a <see cref="FileStreamResult"/> which constains an excel file created from a <see cref="XLWorkbook"/>
/// </summary>
/// <param name="workbook"></param>
/// <param name="fileName"></param>
/// <returns></returns>
public static FileStreamResult CreateFile(this XLWorkbook workbook, string fileName)
namespace CpfCnpj
{
public static class CpfCnpjUtils
{
public static bool IsValid(string cpfCnpj)
{
return (IsCpf(cpfCnpj) || IsCnpj(cpfCnpj));
}
private static bool IsCpf(string cpf)
@flpinheiro
flpinheiro / RadioButton.tex
Created October 23, 2020 20:09
Radio Button example to be used into tex file.
\documentclass{article}
\usepackage{tikz}
\makeatletter
\newcommand*{\radiobutton}{%
\@ifstar{\@radiobutton0}{\@radiobutton1}%
}
\newcommand*{\@radiobutton}[1]{%
\begin{tikzpicture}
@flpinheiro
flpinheiro / PagedList.cs
Created September 30, 2020 21:31
Paged Collection for Asp.net Core web MVC/API
using Microsoft.AspNetCore.Mvc.Rendering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
namespace Project.Infrastructure.Util
{
public interface IPagedList
{
/*
* Formatar CNPJ, CPF e Retirar a Formatação
*
* Visite nossa página http://www.codigoexpresso.com.br
*
* by Antonio Azevedo
*
* public static string FormatCNPJ(string CNPJ)
* Formata uma string CNPJ
* Informar uma string sem formatacao com o codigo do CNPJ
using System;
namespace Project.Service.Extensions
{
/// <summary>
/// Classe de extensão de formatos.
/// </summary>
public static class Format
{
/// <summary>