using System.Collections.ObjectModel; using System.Text.Json; using System.Text.Json.Serialization; namespace View_by_Distance.Instance.Models.Binder; public class Place { public string? Title { get; set; } public DegreesMinutesSeconds? Latitude { get; set; } public DegreesMinutesSeconds? Longitude { get; set; } public override string ToString() { string result = JsonSerializer.Serialize(this, BinderPlaceSourceGenerationContext.Default.Place); return result; } private static Models.Place Get(Place? Place) { Models.Place result; Models.DegreesMinutesSeconds latitude; Models.DegreesMinutesSeconds longitude; if (Place is null) throw new NullReferenceException(nameof(Place)); if (Place.Title is null) throw new NullReferenceException(nameof(Place.Title)); if (Place.Latitude is null) throw new NullReferenceException(nameof(Place.Latitude)); if (Place.Latitude.Degrees is null) throw new NullReferenceException(nameof(Place.Latitude.Degrees)); if (Place.Latitude.Minutes is null) throw new NullReferenceException(nameof(Place.Latitude.Minutes)); if (Place.Latitude.Seconds is null) throw new NullReferenceException(nameof(Place.Latitude.Seconds)); if (Place.Longitude is null) throw new NullReferenceException(nameof(Place.Longitude)); latitude = new(Place.Latitude.Degrees.Value, Place.Latitude.Minutes.Value, Place.Latitude.Seconds.Value); if (Place.Longitude.Degrees is null) throw new NullReferenceException(nameof(Place.Longitude.Degrees)); if (Place.Longitude.Minutes is null) throw new NullReferenceException(nameof(Place.Longitude.Minutes)); if (Place.Longitude.Seconds is null) throw new NullReferenceException(nameof(Place.Longitude.Seconds)); longitude = new(Place.Longitude.Degrees.Value, Place.Longitude.Minutes.Value, Place.Longitude.Seconds.Value); result = new( Place.Title, latitude, longitude ); return result; } internal static ReadOnlyCollection GetPlaces(string[]? places) { List results = []; if (places is not null) { Place? place; foreach (string jsonElement in places) { place = JsonSerializer.Deserialize(jsonElement, BinderPlaceSourceGenerationContext.Default.Place); results.Add(Get(place)); } } return new(results); } } [JsonSourceGenerationOptions(WriteIndented = true)] [JsonSerializable(typeof(Place))] internal partial class BinderPlaceSourceGenerationContext : JsonSerializerContext { }