@@ -18,16 +18,37 @@ namespace GeoJSON.Net.Feature
1818 /// <remarks>
1919 /// See https://tools.ietf.org/html/rfc7946#section-3.2
2020 /// </remarks>
21- public class Feature : GeoJSONObject , IEqualityComparer < Feature > , IEquatable < Feature >
21+ public class Feature : Feature < IGeometryObject >
2222 {
23+ [ JsonConstructor ]
24+ public Feature ( IGeometryObject geometry , Dictionary < string , object > properties = null , string id = null )
25+ : base ( geometry , properties , id )
26+ {
27+ }
28+
29+ public Feature ( IGeometryObject geometry , object properties , string id = null )
30+ : base ( geometry , properties , id )
31+ {
32+ }
33+ }
34+
35+
36+ /// <summary>
37+ /// Typed GeoJSON Feature class
38+ /// </summary>
39+ /// <remarks>Returns correctly typed Geometry property</remarks>
40+ /// <typeparam name="TGeometry"></typeparam>
41+ public class Feature < TGeometry > : GeoJSONObject , IEqualityComparer < Feature < TGeometry > > , IEquatable < Feature < TGeometry > > where TGeometry : IGeometryObject
42+ {
43+
2344 /// <summary>
2445 /// Initializes a new instance of the <see cref="Feature" /> class.
2546 /// </summary>
2647 /// <param name="geometry">The Geometry Object.</param>
2748 /// <param name="properties">The properties.</param>
2849 /// <param name="id">The (optional) identifier.</param>
2950 [ JsonConstructor ]
30- public Feature ( IGeometryObject geometry , Dictionary < string , object > properties = null , string id = null )
51+ public Feature ( TGeometry geometry , Dictionary < string , object > properties = null , string id = null )
3152 {
3253 Geometry = geometry ;
3354 Properties = properties ?? new Dictionary < string , object > ( ) ;
@@ -45,7 +66,7 @@ public Feature(IGeometryObject geometry, Dictionary<string, object> properties =
4566 /// properties
4667 /// </param>
4768 /// <param name="id">The (optional) identifier.</param>
48- public Feature ( IGeometryObject geometry , object properties , string id = null )
69+ public Feature ( TGeometry geometry , object properties , string id = null )
4970 {
5071 Geometry = geometry ;
5172 Id = id ;
@@ -79,7 +100,7 @@ public Feature(IGeometryObject geometry, object properties, string id = null)
79100 /// </value>
80101 [ JsonProperty ( PropertyName = "geometry" , Required = Required . AllowNull ) ]
81102 [ JsonConverter ( typeof ( GeometryConverter ) ) ]
82- public IGeometryObject Geometry { get ; private set ; }
103+ public TGeometry Geometry { get ; private set ; }
83104
84105 /// <summary>
85106 /// Gets or sets the id.
@@ -95,40 +116,41 @@ public Feature(IGeometryObject geometry, object properties, string id = null)
95116 [ JsonProperty ( PropertyName = "properties" , Required = Required . AllowNull ) ]
96117 public Dictionary < string , object > Properties { get ; private set ; }
97118
98- #region IEqualityComparer, IEquatable
119+
120+ #region IEqualityComparer, IEquatable
99121
100122 /// <summary>
101123 /// Determines whether the specified object is equal to the current object
102124 /// </summary>
103125 public override bool Equals ( object obj )
104126 {
105- return Equals ( this , obj as Feature ) ;
127+ return Equals ( this , obj as Feature < TGeometry > ) ;
106128 }
107129
108130 /// <summary>
109131 /// Determines whether the specified object is equal to the current object
110132 /// </summary>
111- public bool Equals ( Feature other )
133+ public bool Equals ( Feature < TGeometry > other )
112134 {
113135 return Equals ( this , other ) ;
114136 }
115137
116138 /// <summary>
117139 /// Determines whether the specified object instances are considered equal
118140 /// </summary>
119- public bool Equals ( Feature left , Feature right )
141+ public bool Equals ( Feature < TGeometry > left , Feature < TGeometry > right )
120142 {
121143 if ( base . Equals ( left , right ) )
122144 {
123- return GetHashCode ( left ) == GetHashCode ( right ) ;
145+ return GetHashCode ( left ) == GetHashCode ( right ) ;
124146 }
125147 return false ;
126148 }
127149
128150 /// <summary>
129151 /// Determines whether the specified object instances are considered equal
130152 /// </summary>
131- public static bool operator == ( Feature left , Feature right )
153+ public static bool operator == ( Feature < TGeometry > left , Feature < TGeometry > right )
132154 {
133155 if ( ReferenceEquals ( left , right ) )
134156 {
@@ -144,7 +166,7 @@ public bool Equals(Feature left, Feature right)
144166 /// <summary>
145167 /// Determines whether the specified object instances are not considered equal
146168 /// </summary>
147- public static bool operator != ( Feature left , Feature right )
169+ public static bool operator != ( Feature < TGeometry > left , Feature < TGeometry > right )
148170 {
149171 return ! ( left == right ) ;
150172 }
@@ -165,12 +187,12 @@ public override int GetHashCode()
165187 /// <summary>
166188 /// Returns the hash code for the specified object
167189 /// </summary>
168- public int GetHashCode ( Feature obj )
190+ public int GetHashCode ( Feature < TGeometry > obj )
169191 {
170192 return obj . GetHashCode ( ) ;
171193 }
172194
173- #endregion
195+ #endregion
174196
175197 }
176198}
0 commit comments