Пример #1
0
 public static WeatherForecastWithTemperatureStruct CreateWeatherForecastWithTemperatureStruct()
 {
     var weatherForecast = new WeatherForecastWithTemperatureStruct
     {
         Date = DateTime.Parse("2019-08-01"),
         TemperatureCelsius = new Temperature(25, true),
         Summary = "Hot"
     };
     return weatherForecast;
 }
        public static void Run()
        {
            string jsonString;
            WeatherForecastWithTemperatureStruct weatherForecast = WeatherForecastFactories.CreateWeatherForecastWithTemperatureStruct();

            weatherForecast.DisplayPropertyValues();

            // <SnippetSerialize>
            var serializeOptions = new JsonSerializerOptions
            {
                WriteIndented = true
            };

            jsonString = JsonSerializer.Serialize(weatherForecast, serializeOptions);
            // </SnippetSerialize>
            Console.WriteLine($"JSON output:\n{jsonString}\n");

            // <SnippetDeserialize>
            weatherForecast = JsonSerializer.Deserialize <WeatherForecastWithTemperatureStruct>(jsonString);
            weatherForecast.DisplayPropertyValues();
            // </SnippetDeserialize>
        }
Пример #3
0
 public static void DisplayPropertyValues(this WeatherForecastWithTemperatureStruct wf)
 {
     Utilities.DisplayPropertyValues(wf);
     Console.WriteLine();
 }