@@ -104,29 +104,13 @@ static StringContent SerializeRequest(UsageModel model)
104104 var serializer = new SimpleJsonSerializer ( ) ;
105105 var dictionary = new Dictionary < string , object >
106106 {
107- { ToJsonPropertyName ( "Dimensions" ) , ToStringDictionary ( model . Dimensions ) } ,
108- { ToJsonPropertyName ( "Measures" ) , ToObjectDictionary ( model . Measures ) }
107+ { ToJsonPropertyName ( "Dimensions" ) , ToModelDictionary ( model . Dimensions ) } ,
108+ { ToJsonPropertyName ( "Measures" ) , ToModelDictionary ( model . Measures ) }
109109 } ;
110110 return new StringContent ( serializer . Serialize ( dictionary ) , Encoding . UTF8 , "application/json" ) ;
111111 }
112112
113- static Dictionary < string , string > ToStringDictionary ( object model )
114- {
115- var dict = new Dictionary < string , string > ( ) ;
116- var type = model . GetType ( ) ;
117-
118- foreach ( var prop in type . GetProperties ( ) )
119- {
120- if ( prop . PropertyType . IsValueType || prop . PropertyType == typeof ( string ) )
121- {
122- dict . Add ( ToJsonPropertyName ( prop . Name ) , prop . GetValue ( model ) . ToString ( ) ) ;
123- }
124- }
125-
126- return dict ;
127- }
128-
129- static Dictionary < string , object > ToObjectDictionary ( object model )
113+ static Dictionary < string , object > ToModelDictionary ( object model )
130114 {
131115 var dict = new Dictionary < string , object > ( ) ;
132116 var type = model . GetType ( ) ;
@@ -137,11 +121,25 @@ static Dictionary<string, object> ToObjectDictionary(object model)
137121 {
138122 dict . Add ( ToJsonPropertyName ( prop . Name ) , prop . GetValue ( model ) ) ;
139123 }
124+ else
125+ {
126+ var value = prop . GetValue ( model ) ;
127+
128+ if ( value == null )
129+ {
130+ dict . Add ( ToJsonPropertyName ( prop . Name ) , value ) ;
131+ }
132+ else
133+ {
134+ dict . Add ( ToJsonPropertyName ( prop . Name ) , ToModelDictionary ( value ) ) ;
135+ }
136+ }
140137 }
141138
142139 return dict ;
143140 }
144141
142+
145143 /// <summary>
146144 /// Convert from PascalCase to camelCase.
147145 /// </summary>
0 commit comments