/// <summary> /// Converts an instance of <see cref="GeoObject"/> to a GeoJSON representation. /// </summary> /// <returns></returns> public override string ToString() { using MemoryStream stream = new MemoryStream(); using Utf8JsonWriter writer = new Utf8JsonWriter(stream); GeoJsonConverter.Write(writer, this); writer.Flush(); return(Encoding.UTF8.GetString(stream.ToArray())); }
/// <summary> /// Converts an instance of <see cref="GeoObject"/> to a GeoJSON representation. /// </summary> /// <returns></returns> public override string ToString() { if (_serialized == null) { using MemoryStream stream = new MemoryStream(); using Utf8JsonWriter writer = new Utf8JsonWriter(stream); GeoJsonConverter.Write(writer, this); _serialized = Encoding.UTF8.GetString(stream.ToArray()); } return(_serialized); }
/// <summary> /// Serializes this instance using the provided <see cref="Utf8JsonWriter"/>. /// </summary> /// <param name="writer">The <see cref="Utf8JsonWriter"/> to write to.</param> #pragma warning disable AZC0014 // do not expose Json types in public APIs public void WriteTo(Utf8JsonWriter writer) #pragma warning restore AZC0014 { Argument.AssertNotNull(writer, nameof(writer)); GeoJsonConverter.Write(writer, this); }
/// <summary> /// Parses an instance of see <see cref="GeoObject"/> from provided JSON representation. /// </summary> /// <param name="json">The GeoJSON representation of an object.</param> /// <returns>The resulting <see cref="GeoObject"/> object.</returns> public static GeoObject Parse(string json) { using JsonDocument jsonDocument = JsonDocument.Parse(json); return(GeoJsonConverter.Read(jsonDocument.RootElement)); }