This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Microsoft.AspNetCore.JsonPatch; | |
| using System.Text.Json; | |
| var patch = JsonSerializer.Deserialize<JsonPatchDocument<Product>>(patchJson); | |
| patch!.ApplyTo(product); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Text.Json.Serialization; | |
| // This would throw at runtime if Employee has circular references | |
| [JsonSerializable(typeof(Employee))] | |
| internal partial class AppJsonContext : JsonSerializerContext { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Text.Json; | |
| var options = JsonSerializerOptions.Strict; | |
| var user = JsonSerializer.Deserialize<LoginRequest>(jsonPayload, options); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Text.Json; | |
| using System.Text.Json.Serialization; | |
| var options = new JsonSerializerOptions | |
| { | |
| AllowDuplicateProperties = false, | |
| UnmappedMemberHandling = JsonUnmappedMemberHandling.Disallow, | |
| PropertyNameCaseInsensitive = false, | |
| RespectNullableAnnotations = true, | |
| RespectRequiredConstructorParameters = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Net.Http; | |
| using var client = new HttpClient(); | |
| string html = await client.GetStringAsync("https://example.com"); // Uses TLS 1.3 on macOS automatically |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
NewerOlder