public static WeatherForecastWithConverterAttribute CreateWeatherForecastWithConverterAttribute() { var weatherForecast = new WeatherForecastWithConverterAttribute { Date = DateTime.Parse("2019-08-01"), TemperatureCelsius = 25, Summary = "Hot" }; return weatherForecast; }
public static void Run() { string jsonString; WeatherForecastWithConverterAttribute weatherForecast = WeatherForecastFactories.CreateWeatherForecastWithConverterAttribute(); weatherForecast.DisplayPropertyValues(); // <SnippetSerialize> var serializeOptions = new JsonSerializerOptions(); serializeOptions.WriteIndented = true; jsonString = JsonSerializer.Serialize(weatherForecast, serializeOptions); // </SnippetSerialize> Console.WriteLine($"JSON output:\n{jsonString}\n"); // <SnippetDeserialize> weatherForecast = JsonSerializer.Deserialize <WeatherForecastWithConverterAttribute>(jsonString); // </SnippetDeserialize> weatherForecast.DisplayPropertyValues(); }
public static void DisplayPropertyValues(this WeatherForecastWithConverterAttribute wf) { Utilities.DisplayPropertyValues(wf); Console.WriteLine(); }