@@ -549,15 +549,9 @@ private object ReadFromStream(Type type, Stream readStream, HttpContent content,
549549 public object Deserialize ( Type objectType , Stream readStream , JsonReader reader , JsonSerializer serializer )
550550 {
551551 object retval = Activator . CreateInstance ( objectType ) ;
552- PropertyInfo [ ] props = objectType . GetProperties ( ) ;
553-
554- //TODO: This could get expensive...cache these maps per type, so we only build the map once?
555- IDictionary < string , PropertyInfo > propMap = new Dictionary < string , PropertyInfo > ( ) ;
556- foreach ( PropertyInfo prop in props )
557- {
558- propMap [ FormatPropertyName ( prop . Name ) ] = prop ;
559- }
560552
553+ IDictionary < string , PropertyInfo > propMap = ModelManager . Instance . GetPropertyMap ( objectType ) ;
554+
561555 if ( reader . TokenType != JsonToken . StartObject ) throw new JsonReaderException ( String . Format ( "Expected JsonToken.StartObject, got {0}" , reader . TokenType . ToString ( ) ) ) ;
562556 reader . Read ( ) ; // Burn the StartObject token
563557 do
@@ -640,13 +634,7 @@ private void DeserializeLinkedResources(object obj, Stream readStream, JsonReade
640634 //reader.Read();
641635 if ( reader . TokenType != JsonToken . StartObject ) throw new JsonSerializationException ( "'links' property is not an object!" ) ;
642636
643- //TODO: Redundant, already done in Deserialize method...optimize?
644- PropertyInfo [ ] props = obj . GetType ( ) . GetProperties ( ) ;
645- IDictionary < string , PropertyInfo > propMap = new Dictionary < string , PropertyInfo > ( ) ;
646- foreach ( PropertyInfo prop in props )
647- {
648- propMap [ FormatPropertyName ( prop . Name ) ] = prop ;
649- }
637+ IDictionary < string , PropertyInfo > propMap = ModelManager . Instance . GetPropertyMap ( obj . GetType ( ) ) ;
650638
651639 while ( reader . Read ( ) )
652640 {
@@ -809,6 +797,7 @@ private Type GetSingleType(Type type)//dynamic value = null)
809797 return type ;
810798 }
811799
800+ //TODO: Should this move to ModelManager? Could be cached there to improve performance?
812801 public static string FormatPropertyName ( string propertyName )
813802 {
814803 string result = propertyName . Substring ( 0 , 1 ) . ToLower ( ) + propertyName . Substring ( 1 ) ;
0 commit comments