@@ -119,18 +119,18 @@ public override Task WriteToStreamAsync(System.Type type, object value, Stream w
119119 else
120120 {
121121 Type valtype = GetSingleType ( value . GetType ( ) ) ;
122- if ( IsMany ( value . GetType ( ) ) )
122+ if ( _modelManager . IsSerializedAsMany ( value . GetType ( ) ) )
123123 aggregator . AddPrimary ( valtype , ( IEnumerable < object > ) value ) ;
124124 else
125125 aggregator . AddPrimary ( valtype , value ) ;
126126
127127 //writer.Formatting = Formatting.Indented;
128128
129- var root = GetJsonKeyForType ( type , value ) ;
129+ var root = _modelManager . GetJsonKeyForType ( type ) ;
130130
131131 writer . WriteStartObject ( ) ;
132132 writer . WritePropertyName ( root ) ;
133- if ( IsMany ( value . GetType ( ) ) )
133+ if ( _modelManager . IsSerializedAsMany ( value . GetType ( ) ) )
134134 this . SerializeMany ( value , writeStream , writer , serializer , aggregator ) ;
135135 else
136136 this . Serialize ( value , writeStream , writer , serializer , aggregator ) ;
@@ -422,7 +422,7 @@ protected void SerializeLinkedResources(Stream writeStream, JsonWriter writer, J
422422 foreach ( KeyValuePair < Type , KeyValuePair < JsonWriter , StringWriter > > apair in writers )
423423 {
424424 apair . Value . Key . WriteEnd ( ) ; // close off the array
425- writer . WritePropertyName ( GetJsonKeyForType ( apair . Key ) ) ;
425+ writer . WritePropertyName ( _modelManager . GetJsonKeyForType ( apair . Key ) ) ;
426426 writer . WriteRawValue ( apair . Value . Value . ToString ( ) ) ; // write the contents of the type JsonWriter's StringWriter to the main JsonWriter
427427 }
428428
@@ -445,7 +445,7 @@ private object ReadFromStream(Type type, Stream readStream, HttpContent content,
445445 {
446446 object retval = null ;
447447 Type singleType = GetSingleType ( type ) ;
448- var pripropname = GetJsonKeyForType ( type ) ;
448+ var pripropname = _modelManager . GetJsonKeyForType ( type ) ;
449449 var contentHeaders = content == null ? null : content . Headers ;
450450
451451 // If content length is 0 then return default value for this type
@@ -522,7 +522,7 @@ private object ReadFromStream(Type type, Stream readStream, HttpContent content,
522522 */
523523 if ( retval != null )
524524 {
525- if ( ! type . IsAssignableFrom ( retval . GetType ( ) ) && IsMany ( type ) )
525+ if ( ! type . IsAssignableFrom ( retval . GetType ( ) ) && _modelManager . IsSerializedAsMany ( type ) )
526526 {
527527 IList list = ( IList ) Activator . CreateInstance ( typeof ( List < > ) . MakeGenericType ( singleType ) ) ;
528528 list . Add ( retval ) ;
@@ -770,42 +770,11 @@ private object DeserializePrimitive(Type type, JsonReader reader)
770770
771771 #endregion
772772
773- //TODO: Remove shell function, call _modelManager.GetJsonKeyForType directly.
774- private string GetJsonKeyForType ( Type type , dynamic value = null )
773+ private Type GetSingleType ( Type type ) //dynamic value = null)
775774 {
776- return _modelManager . GetJsonKeyForType ( type ) ;
775+ return _modelManager . IsSerializedAsMany ( type ) ? _modelManager . GetElementType ( type ) : type ;
777776 }
778777
779- //private string GetPropertyName(Type type)
780- //{
781- // return FormatPropertyName(PluralizationService.Pluralize(type.Name));
782- //}
783-
784- internal static bool IsMany ( Type type )
785- {
786- return
787- type . IsArray ||
788- ( type . GetInterfaces ( ) . Contains ( typeof ( IEnumerable ) ) && type . IsGenericType ) ;
789- }
790-
791- internal static Type GetSingleType ( Type type ) //dynamic value = null)
792- {
793- if ( IsMany ( type ) )
794- if ( type . IsGenericType )
795- return type . GetGenericArguments ( ) [ 0 ] ;
796- else
797- return type . GetElementType ( ) ;
798- return type ;
799- }
800-
801- /*
802- public static string FormatPropertyName(string propertyName)
803- {
804- string result = propertyName.Substring(0, 1).ToLower() + propertyName.Substring(1);
805- return result;
806- }
807- */
808-
809778 protected object GetById ( Type type , string id )
810779 {
811780 // Only good for creating dummy relationship objects...
@@ -815,13 +784,6 @@ protected object GetById(Type type, string id)
815784 return retval ;
816785 }
817786
818- /*
819- protected PropertyInfo GetIdProperty(Type type)
820- {
821- return type.GetProperty("Id");
822- }
823- */
824-
825787 protected string GetValueForIdProperty ( PropertyInfo idprop , object obj )
826788 {
827789 if ( idprop != null )
0 commit comments