< Summary

Class:Azure.Core.GeoJson.GeoObject
Assembly:Azure.Core.Experimental
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core.Experimental\src\Spatial\GeoObject.cs
Covered lines:8
Uncovered lines:9
Coverable lines:17
Total lines:73
Line coverage:47% (8 of 17)
Covered branches:0
Total branches:2
Branch coverage:0% (0 of 2)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
.ctor(...)-100%100%
get_BoundingBox()-100%100%
get_AdditionalProperties()-100%100%
ToString()-0%0%
Parse(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core.Experimental\src\Spatial\GeoObject.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Buffers;
 5using System.Collections.Generic;
 6using System.Collections.ObjectModel;
 7using System.IO;
 8using System.Linq;
 9using System.Text;
 10using System.Text.Json;
 11
 12namespace Azure.Core.GeoJson
 13{
 14    /// <summary>
 15    /// A base type for all spatial types.
 16    /// </summary>
 17    public abstract class GeoObject
 18    {
 219        internal static readonly IReadOnlyDictionary<string, object?> DefaultProperties = new ReadOnlyDictionary<string,
 20        private string? _serialized;
 21
 22        /// <summary>
 23        /// Initializes a new instance of <see cref="GeoObject"/>.
 24        /// </summary>
 25        /// <param name="boundingBox">The <see cref="GeoBoundingBox"/> to use.</param>
 26        /// <param name="additionalProperties">The set of additional properties associated with the <see cref="GeoObject
 37027        protected GeoObject(GeoBoundingBox? boundingBox, IReadOnlyDictionary<string, object?> additionalProperties)
 28        {
 37029            Argument.AssertNotNull(additionalProperties, nameof(additionalProperties));
 30
 37031            BoundingBox = boundingBox;
 37032            AdditionalProperties = additionalProperties;
 37033        }
 34
 35        /// <summary>
 36        /// Represents information about the coordinate range of the <see cref="GeoObject"/>.
 37        /// </summary>
 15838        public GeoBoundingBox? BoundingBox { get; }
 39
 40        /// <summary>
 41        /// Gets a dictionary of additional properties associated with the <see cref="GeoObject"/>.
 42        /// </summary>
 16243        public IReadOnlyDictionary<string, object?> AdditionalProperties { get; }
 44
 45        /// <summary>
 46        /// Converts an instance of <see cref="GeoObject"/> to a GeoJSON representation.
 47        /// </summary>
 48        /// <returns></returns>
 49        public override string ToString()
 50        {
 051            if (_serialized == null)
 52            {
 053                using MemoryStream stream = new MemoryStream();
 054                using Utf8JsonWriter writer = new Utf8JsonWriter(stream);
 055                GeoJsonConverter.Write(writer, this);
 056                _serialized = Encoding.UTF8.GetString(stream.ToArray());
 57            }
 58
 059            return _serialized;
 60        }
 61
 62        /// <summary>
 63        /// Parses an instance of see <see cref="GeoObject"/> from provided JSON representation.
 64        /// </summary>
 65        /// <param name="json">The GeoJSON representation of an object.</param>
 66        /// <returns>The resulting <see cref="GeoObject"/> object.</returns>
 67        public static GeoObject Parse(string json)
 68        {
 069            using JsonDocument jsonDocument = JsonDocument.Parse(json);
 070            return GeoJsonConverter.Read(jsonDocument.RootElement);
 071        }
 72    }
 73}