Skip to content

Instantly share code, notes, and snippets.

View pedrovasconcellos's full-sized avatar

Pedro Vasconcellos pedrovasconcellos

View GitHub Profile
@pedrovasconcellos
pedrovasconcellos / Pagination.cs
Last active April 28, 2023 20:01
Pagination
public async Task<IActionResult> Example(int? page, int? rows)
{
IList<object> entities = await _service.Get();
if (page != null && page > 0 && rows != null && rows > 0)
{
entities = query.Skip((int)(rows * (page - 1))).Take((int)rows).ToList();
}
else
entities = query.ToList();
@pedrovasconcellos
pedrovasconcellos / ObjectExtension.cs
Created December 31, 2020 02:59
ObjectExtension with CopyObject and CopyPropertiesTo
using System.IO;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using System.Linq;
namespace Vasconcellos.Extensions
{
public static class ObjectExtension
{
/// <summary>
@pedrovasconcellos
pedrovasconcellos / EnumExtension.cs
Last active April 12, 2023 19:04
EnumExtension with GetDescription
using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
public static class EnumExtension
{
public static string GetDescription<TEnum>(this TEnum value) where TEnum : Enum
{
FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
@pedrovasconcellos
pedrovasconcellos / EnumExtensions.cs
Last active June 7, 2023 17:38
InvalidToDefaultEnumConverter
public static class EnumExtensions
{
public static T? GetDefaultValue<T>() where T : Enum
{
var enumType = typeof(T);
var defaultValueAttribute = Attribute
.GetCustomAttribute(enumType, typeof(DefaultValueAttribute)) as DefaultValueAttribute;
if (defaultValueAttribute is not null &&
defaultValueAttribute.Value is T)
@pedrovasconcellos
pedrovasconcellos / ResultT.rs
Last active April 28, 2023 20:15
Result class in Rust Language
use std::collections::HashMap;
pub struct ResultT<T> {
response: Option<T>,
errors: HashMap<String, String>,
}
impl<T> ResultT<T> {
pub fn new() -> Self {
ResultT {
@pedrovasconcellos
pedrovasconcellos / ResultT.go
Created April 28, 2023 20:19
Result class in Go Language
type ResultT struct {
Response interface{}
Errors map[string]string
}
func NewResultT() ResultT {
return ResultT{
Response: nil,
Errors: make(map[string]string),
}