diff --git a/src/GeoJSON.Net/Features/Feature.cs b/src/GeoJSON.Net/Features/Feature.cs index 2607b5cf..3856bd55 100644 --- a/src/GeoJSON.Net/Features/Feature.cs +++ b/src/GeoJSON.Net/Features/Feature.cs @@ -12,14 +12,28 @@ namespace GeoJSON.Net.Features { - /// - /// A GeoJSON Feature Object; generic version for strongly typed - /// and - /// - /// - /// See https://tools.ietf.org/html/rfc7946#section-3.2 - /// - public class Feature : GeoJSONObject, IEquatable> + /// + /// A GeoJSON Feature Object; generic version for strongly typed + /// and + /// + /// + /// See https://tools.ietf.org/html/rfc7946#section-3.2 + /// + public interface IFeature where TGeometry : IGeometryObject + { + string Id { get; } + TGeometry Geometry { get; } + TProps Properties { get; } + } + + /// + /// A GeoJSON Feature Object; generic version for strongly typed + /// and + /// + /// + /// See https://tools.ietf.org/html/rfc7946#section-3.2 + /// + public class Feature : GeoJSONObject, IFeature, IEquatable> where TGeometry : IGeometryObject { [JsonConstructor] diff --git a/src/GeoJSON.Net/Features/FeatureCollection.cs b/src/GeoJSON.Net/Features/FeatureCollection.cs index 27239d32..23c6bc0b 100644 --- a/src/GeoJSON.Net/Features/FeatureCollection.cs +++ b/src/GeoJSON.Net/Features/FeatureCollection.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Newtonsoft.Json; using System.Linq; +using GeoJSON.Net.Geometry; namespace GeoJSON.Net.Features { @@ -119,4 +120,114 @@ public int GetHashCode(FeatureCollection other) #endregion } + + public class FeatureCollection : FeatureCollection, IEqualityComparer>, IEquatable> + { + /// + /// Initializes a new instance of the class. + /// + public FeatureCollection() : this(new List>()) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The features. + public FeatureCollection(List> features) + { + if (features == null) + { + throw new ArgumentNullException(nameof(features)); + } + + Features = features; + } + + public override GeoJSONObjectType Type => GeoJSONObjectType.FeatureCollection; + + /// + /// Gets the features. + /// + /// The features. + [JsonProperty(PropertyName = "features", Required = Required.Always)] + new public List> Features { get; private set; } + + #region IEqualityComparer, IEquatable + + /// + /// Determines whether the specified object is equal to the current object + /// + public override bool Equals(object obj) + { + return Equals(this, obj as FeatureCollection); + } + + /// + /// Determines whether the specified object is equal to the current object + /// + public bool Equals(FeatureCollection other) + { + return Equals(this, other); + } + + /// + /// Determines whether the specified object instances are considered equal + /// + public bool Equals(FeatureCollection left, FeatureCollection right) + { + if (base.Equals(left, right)) + { + return left.Features.SequenceEqual(right.Features); + } + return false; + } + + /// + /// Determines whether the specified object instances are considered equal + /// + public static bool operator ==(FeatureCollection left, FeatureCollection right) + { + if (ReferenceEquals(left, right)) + { + return true; + } + if (ReferenceEquals(null, right)) + { + return false; + } + return left != null && left.Equals(right); + } + + /// + /// Determines whether the specified object instances are not considered equal + /// + public static bool operator !=(FeatureCollection left, FeatureCollection right) + { + return !(left == right); + } + + /// + /// Returns the hash code for this instance + /// + public override int GetHashCode() + { + int hash = base.GetHashCode(); + foreach (var feature in Features) + { + hash = (hash * 397) ^ feature.GetHashCode(); + } + return hash; + } + + /// + /// Returns the hash code for the specified object + /// + public int GetHashCode(FeatureCollection other) + { + return other.GetHashCode(); + } + + #endregion + } } \ No newline at end of file