Skip to content

Instantly share code, notes, and snippets.

View marcominerva's full-sized avatar
🏠
Working from home

Marco Minerva marcominerva

🏠
Working from home
View GitHub Profile
@marcominerva
marcominerva / Directory.Build.proprs
Created April 8, 2024 13:20
Reduce path in Stack Trace
<Project>
<PropertyGroup>
<PathMap>$(MSBuildThisFileDirectory)=./</PathMap>
</PropertyGroup>
</Project>
@marcominerva
marcominerva / Slugify
Last active November 15, 2023 15:25
Slugify routes
builder.Services.AddControllers(options =>
{
options.Conventions.Add(new RouteTokenTransformerConvention(new SlugifyParameterTransformer()));
});
public class SlugifyParameterTransformer : IOutboundParameterTransformer
{
public string? TransformOutbound(object? value)
=> value is null ? null
: Regex.Replace(value.ToString()!, "([a-z])([A-Z])", "$1-$2", RegexOptions.CultureInvariant).ToLowerInvariant();
@marcominerva
marcominerva / .editorconfig
Last active March 26, 2024 13:36
.editorconfig
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true
[*]
#### Core EditorConfig Options ####
# Indentation and spacing
indent_size = 4
indent_style = space
<#@ template hostSpecific="true" debug="false" #>
<#@ assembly name="Microsoft.EntityFrameworkCore" #>
<#@ assembly name="Microsoft.EntityFrameworkCore.Design" #>
<#@ assembly name="Microsoft.EntityFrameworkCore.Relational" #>
<#@ assembly name="Microsoft.Extensions.DependencyInjection.Abstractions" #>
<#@ parameter name="EntityType" type="Microsoft.EntityFrameworkCore.Metadata.IEntityType" #>
<#@ parameter name="Options" type="Microsoft.EntityFrameworkCore.Scaffolding.ModelCodeGenerationOptions" #>
<#@ parameter name="NamespaceHint" type="System.String" #>
<#@ parameter name="ProjectDefaultNamespace" type="System.String" #>
<#@ import namespace="System.Collections.Generic" #>
@marcominerva
marcominerva / TimeOnlyConverter.cs
Created January 7, 2022 15:10
TimeOnly Converter & Comparer for Entity FrameworkCore 6.0
public class TimeOnlyConverter : ValueConverter<TimeOnly, TimeSpan>
{
public TimeOnlyConverter() : base(
timeOnly => timeOnly.ToTimeSpan(),
timeSpan => TimeOnly.FromTimeSpan(timeSpan))
{
}
}
public class TimeOnlyComparer : ValueComparer<TimeOnly>
@marcominerva
marcominerva / DateOnlyConverter.cs
Created January 7, 2022 15:09
DateOnly Converter & Comparer for Entity Framework Core 6.0
public class DateOnlyConverter : ValueConverter<DateOnly, DateTime>
{
public DateOnlyConverter() : base(
dateOnly => dateOnly.ToDateTime(TimeOnly.MinValue),
dateTime => DateOnly.FromDateTime(dateTime))
{
}
}
public class DateOnlyComparer : ValueComparer<DateOnly>
@marcominerva
marcominerva / TimeOnlyConverter.cs
Last active October 20, 2022 20:07
TimeOnlyConverter for System.Text.Json in .NET 6.0
public class TimeOnlyConverter : JsonConverter<TimeOnly>
{
private readonly string serializationFormat;
public TimeOnlyConverter() : this(null)
{
}
public TimeOnlyConverter(string? serializationFormat)
{
@marcominerva
marcominerva / DateOnlyConverter.cs
Last active October 20, 2022 20:07
DateOnlyConverter for System.Text.Json in .NET 6.0
public class DateOnlyConverter : JsonConverter<DateOnly>
{
private readonly string serializationFormat;
public DateOnlyConverter() : this(null)
{
}
public DateOnlyConverter(string? serializationFormat)
{
@marcominerva
marcominerva / Frullino.cs
Last active March 25, 2021 10:47
Il codice perfetto
for (var frullino = 0; frullino < 42; frullino++)
{
System.Console.WriteLine("Taggia");
}
@marcominerva
marcominerva / AsyncLock.cs
Last active April 17, 2020 13:49
How to implement a simple lock in an asynchronous workflow
using System.Threading.Tasks;
namespace System.Threading
{
public class AsyncLock : IDisposable
{
private readonly SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1, 1);
public async Task<AsyncLock> LockAsync()
{