using System.ComponentModel; namespace ZeroFramework.DeviceCenter.Domain.Aggregates.DeviceAggregate { /// /// Represents a geographical location that is determined by latitude and longitude coordinates /// [TypeConverter(typeof(GeoCoordinateTypeConverter))] public record GeoCoordinate { /// /// Gets or sets the latitude of the GeoCoordinate. /// public double Latitude { get; } /// /// Gets or sets the longitude of the GeoCoordinate. /// public double Longitude { get; } /// /// Constructors /// public GeoCoordinate(double latitude, double longitude) { Latitude = latitude; Longitude = longitude; } /// /// Returns a string that represents the current object. /// public override string ToString() => $"{Latitude},{Longitude}"; /// /// Deconstructing a user-defined type with an extension method /// public void Deconstruct(out double latitude, out double longitude) { latitude = Latitude; longitude = Longitude; } /// /// Implicit conversions /// public static implicit operator string(GeoCoordinate geo) => geo.ToString(); /// /// Explicit conversions /// public static explicit operator GeoCoordinate?(string str) { GeoCoordinate? geoCoordinate = null; if (!string.IsNullOrWhiteSpace(str)) { double[] arr = Array.ConvertAll(str.Split(','), i => Convert.ToDouble(i)); geoCoordinate = new GeoCoordinate(arr.First(), arr.Last()); } return geoCoordinate; } } }