99 [ ExcludeFromCodeCoverage ]
1010 public abstract class Feature
1111 {
12- [ JsonConverter ( typeof ( StringConverter ) ) ]
12+ [ JsonConverter ( typeof ( FeatureIdConverter ) ) ]
1313 public string Id { get ; set ; }
1414
15+ [ JsonConverter ( typeof ( FeaturePropertiesConverter ) ) ]
1516 public IDictionary < string , object > Properties { get ; set ; }
1617 public BoundingBox BBox { get ; set ; }
1718
@@ -30,8 +31,7 @@ public sealed class Feature<TGeometry> : Feature
3031
3132 public TGeometry Geometry
3233 {
33- get
34- {
34+ get {
3535 if ( _geometry != null && _geometry . Id != Id )
3636 {
3737 _geometry . Id = Id ;
@@ -55,7 +55,7 @@ public Feature(TGeometry geometry, IDictionary<string, object> properties) : thi
5555 public Feature ( string id , TGeometry geometry , IDictionary < string , object > properties ) : base ( id , properties ) => Geometry = geometry ;
5656 }
5757
58- internal sealed class StringConverter : JsonConverter < string >
58+ internal sealed class FeatureIdConverter : JsonConverter < string >
5959 {
6060 public override string Read ( ref Utf8JsonReader reader , Type typeToConvert , JsonSerializerOptions options )
6161 {
@@ -70,4 +70,27 @@ public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonS
7070
7171 public override void Write ( Utf8JsonWriter writer , string value , JsonSerializerOptions options ) => writer . WriteStringValue ( value ) ;
7272 }
73+
74+ internal sealed class FeaturePropertiesConverter : JsonConverter < IDictionary < string , object > >
75+ {
76+ public override IDictionary < string , object > Read ( ref Utf8JsonReader reader , Type typeToConvert , JsonSerializerOptions options ) => JsonSerializer . Deserialize < Dictionary < string , object > > ( ref reader , options ) ;
77+ public override void Write ( Utf8JsonWriter writer , IDictionary < string , object > value , JsonSerializerOptions options )
78+ {
79+ writer . WriteStartObject ( ) ;
80+ foreach ( var kvp in value )
81+ {
82+ writer . WritePropertyName ( kvp . Key ) ;
83+ if ( kvp . Value . GetType ( ) == typeof ( DateTime ) ||
84+ ( kvp . Value . GetType ( ) == typeof ( string ) && DateTime . TryParse ( kvp . Value . ToString ( ) , out _ ) ) )
85+ {
86+ writer . WriteStringValue ( $ "azureMapsControl.datetime:{ kvp . Value } ") ;
87+ }
88+ else
89+ {
90+ writer . WriteStringValue ( JsonSerializer . Serialize ( kvp . Value ) ) ;
91+ }
92+ }
93+ writer . WriteEndObject ( ) ;
94+ }
95+ }
7396}
0 commit comments