Created
November 3, 2023 13:15
-
-
Save habib-sadullaev/e5bccebabf65ad6a3405bff5ced9b496 to your computer and use it in GitHub Desktop.
This file contains 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.Text.Json; | |
var value = new { name = default(string)! }; | |
//method #1 | |
value = (dynamic)JsonSerializer.Deserialize("""{ "name": "xyz" }""", value.GetType())!; | |
Console.WriteLine(value); | |
//method #1 | |
static void tryDeserialize<T>(string json, out T value) => value = JsonSerializer.Deserialize<T>(json)!; | |
tryDeserialize("""{ "name": "abc" }""", out value); | |
Console.WriteLine(value); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment