@@ -13,19 +13,9 @@ internal class DefaultHitJsonConverter : JsonConverter
1313 {
1414 private static readonly ConcurrentDictionary < Type , JsonConverter > _hitTypes = new ConcurrentDictionary < Type , JsonConverter > ( ) ;
1515
16- public override bool CanWrite { get { return false ; } }
17- public override bool CanRead { get { return true ; } }
18-
19-
20- public override void WriteJson ( JsonWriter writer , object value , JsonSerializer serializer )
21- {
22- throw new NotImplementedException ( ) ;
23- }
24-
25- public override bool CanConvert ( Type objectType )
26- {
27- return true ;
28- }
16+ public override bool CanWrite => false ;
17+ public override bool CanRead => true ;
18+ public override bool CanConvert ( Type objectType ) => true ;
2919
3020 public override object ReadJson ( JsonReader reader , Type objectType , object existingValue , JsonSerializer serializer )
3121 {
@@ -40,17 +30,9 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
4030 return converter . ReadJson ( reader , objectType , existingValue , serializer ) ;
4131 }
4232
43- }
44-
45- internal class FieldsSetter
46- {
47- //This method is used through reflection (cached though)
48- // do not remove
49- private static void SetFields < TFieldsType > (
50- Hit < TFieldsType > hit , FieldValues fieldSelection )
51- where TFieldsType : class
33+ public override void WriteJson ( JsonWriter writer , object value , JsonSerializer serializer )
5234 {
53- hit . Fields = fieldSelection ;
35+ throw new NotSupportedException ( ) ;
5436 }
5537 }
5638
@@ -61,6 +43,7 @@ internal class ConcreteTypeConverter<T> : JsonConverter where T : class
6143
6244 public override bool CanWrite => false ;
6345 public override bool CanRead => true ;
46+ public override bool CanConvert ( Type objectType ) => typeof ( IHit < object > ) . IsAssignableFrom ( objectType ) ;
6447
6548 public ConcreteTypeConverter ( ) { }
6649
@@ -83,31 +66,15 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
8366 instance . Fields = new FieldValues ( serializer . GetConnectionSettings ( ) . Inferrer , instance . Fields ) ;
8467 return instance ;
8568 }
86-
87-
8869
8970 public override void WriteJson ( JsonWriter writer , object value , JsonSerializer serializer )
9071 {
91- throw new NotImplementedException ( ) ;
92- }
93-
94- public override bool CanConvert ( Type objectType )
95- {
96- return typeof ( IHit < object > ) . IsAssignableFrom ( objectType ) ;
72+ throw new NotSupportedException ( ) ;
9773 }
9874 }
9975
10076 internal static class ConcreteTypeConverter
10177 {
102- internal static ConcurrentDictionary < Type , Action < object , object > >
103- FieldDelegates = new ConcurrentDictionary < Type , Action < object , object > > ( ) ;
104-
105- internal static ConcurrentDictionary < Type , Type > TypeToFieldTypes =
106- new ConcurrentDictionary < Type , Type > ( ) ;
107-
108- internal static MethodInfo MakeDelegateMethodInfo =
109- typeof ( FieldsSetter ) . GetMethod ( "SetFields" , BindingFlags . Static | BindingFlags . NonPublic ) ;
110-
11178 internal static object GetUsingConcreteTypeConverter < T > (
11279 JsonReader reader , JsonSerializer serializer , ConcreteTypeConverter < T > realConcreteConverter )
11380 where T : class
@@ -116,19 +83,13 @@ internal static object GetUsingConcreteTypeConverter<T>(
11683 var concreteType = GetConcreteTypeUsingSelector ( serializer , realConcreteConverter , jObject ) ;
11784 var hit = GetHitTypeInstance ( concreteType ) ;
11885 PopulateHit ( serializer , jObject . CreateReader ( ) , hit ) ;
119-
120- Action < object , object > cachedLookup ;
121- if ( ConcreteTypeConverter . FieldDelegates . TryGetValue ( concreteType , out cachedLookup ) )
122- return hit ;
123-
124- var generic = ConcreteTypeConverter . MakeDelegateMethodInfo . MakeGenericMethod ( concreteType ) ;
125- cachedLookup = ( h , f ) => generic . Invoke ( null , new [ ] { h , f } ) ;
126- ConcreteTypeConverter . FieldDelegates . TryAdd ( concreteType , cachedLookup ) ;
12786 return hit ;
12887 }
88+
12989 private static void PopulateHit ( JsonSerializer serializer , JsonReader reader , object hit ) {
13090 serializer . Populate ( reader , hit ) ;
13191 }
92+
13293 private static JObject CreateIntermediateJObject ( JsonReader reader )
13394 {
13495 JObject jObject = JObject . Load ( reader ) ;
0 commit comments