Skip to content

Instantly share code, notes, and snippets.

View AnthonyGiretti's full-sized avatar
💭
👍

[MVP] Anthony Giretti AnthonyGiretti

💭
👍
View GitHub Profile
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created March 7, 2026 23:41
ASP.NET Core 10 introduces a native JsonPatch implementation built directly on top of System.Text.Json
using Microsoft.AspNetCore.JsonPatch;
using System.Text.Json;
var patch = JsonSerializer.Deserialize<JsonPatchDocument<Product>>(patchJson);
patch!.ApplyTo(product);
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created March 7, 2026 23:30
.NET 10 adds ReferenceHandler support directly inside JsonSourceGenerationOptionsAttribute
using System.Text.Json.Serialization;
// Giving you fine-grained control over how cycles and references are handled at the source generation leve
[JsonSourceGenerationOptions(ReferenceHandler = JsonKnownReferenceHandler.Preserve)]
[JsonSerializable(typeof(Employee))]
internal partial class AppJsonContext : JsonSerializerContext { }
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created March 7, 2026 23:26
Before .NET 10, Handling circular references with source generation simply wasn't possible
using System.Text.Json.Serialization;
// This would throw at runtime if Employee has circular references
[JsonSerializable(typeof(Employee))]
internal partial class AppJsonContext : JsonSerializerContext { }
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created March 7, 2026 23:23
.NET 10 introduces JsonSerializerOptions.Strict Deserialization
using System.Text.Json;
var options = JsonSerializerOptions.Strict;
var user = JsonSerializer.Deserialize<LoginRequest>(jsonPayload, options);
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created March 7, 2026 23:21
Before .NET 10, enabling strict validation Deserialization
using System.Text.Json;
using System.Text.Json.Serialization;
var options = new JsonSerializerOptions
{
AllowDuplicateProperties = false,
UnmappedMemberHandling = JsonUnmappedMemberHandling.Disallow,
PropertyNameCaseInsensitive = false,
RespectNullableAnnotations = true,
RespectRequiredConstructorParameters = true
@AnthonyGiretti
AnthonyGiretti / Program.cs
Last active January 19, 2026 01:44
.NET 10 Post Quantum Cryptography, example with ML-KEM
using System;
using System.Security.Cryptography;
// 1) Server generates a KEM key pair
using var serverKey = MLKEM.GenerateKey(MLKEMAlgorithm.MLKEM768);
// Export public key
string serverPublicPem = serverKey.ExportSubjectPublicKeyInfoPem();
// 2) Client imports public key
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created January 19, 2026 01:40
.NET 10 Post Quantum Cryptography, example with SLH-DSA
using System;
using System.Security.Cryptography;
byte[] data = "critical firmware update"u8.ToArray();
// Generate SLH-DSA key
using var signingKey = SLHDSA.GenerateKey(SLHDSAAlgorithm.SLHDSA128S);
// Sign the data
byte[] signature = signingKey.SignData(data);
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created January 7, 2026 20:18
.NET 10 , automatic support of TLS 1.3 on macOS
using System.Net.Http;
using var client = new HttpClient();
string html = await client.GetStringAsync("https://example.com"); // Uses TLS 1.3 on macOS automatically
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created January 7, 2026 20:18
.NET 10 new WebSocketStream API
using System.Net.WebSockets;
using System.IO;
// Client side, streaming supported over WebSockets
var client = new ClientWebSocket();
await client.ConnectAsync(new Uri("wss://example.com/upload"), CancellationToken.None);
using var wsStream = WebSocketStream.Create(client);
await using var fileStream = File.OpenRead("bigfile.zip");
@AnthonyGiretti
AnthonyGiretti / Program.cs
Created January 7, 2026 20:10
.NET 10 Post Quantum cryptography; exemple with ML-DSA signature algo
using System;
using System.Security.Cryptography;
byte[] data = "hello PQC"u8.ToArray();
// 1) Generate a post-quantum signature key (ML-DSA)
using var signingKey = MLDSA.GenerateKey(MLDSAAlgorithm.MLDSA65);
// 2) Sign the data
byte[] signature = signingKey.SignData(data);