@@ -85,7 +85,7 @@ public void Can_serialize_Enum()
85
85
expected . Add ( root ) ;
86
86
87
87
Assert . Equal ( expected . ToString ( ) , doc . ToString ( ) ) ;
88
- }
88
+ }
89
89
90
90
[ Fact ]
91
91
public void Can_serialize_simple_POCO_With_DateFormat_Specified ( ) {
@@ -157,6 +157,35 @@ public void Can_serialize_simple_POCO_With_Attribute_Options_Defined() {
157
157
Assert . Equal ( expected . ToString ( ) , doc . ToString ( ) ) ;
158
158
}
159
159
160
+ [ Fact ]
161
+ public void Can_serialize_simple_POCO_With_Attribute_Options_Defined_And_Property_Containing_IList_Elements ( )
162
+ {
163
+ var poco = new WackyPerson
164
+ {
165
+ Name = "Foo" ,
166
+ Age = 50 ,
167
+ Price = 19.95m ,
168
+ StartDate = new DateTime ( 2009 , 12 , 18 , 10 , 2 , 23 ) ,
169
+ ContactData = new ContactData
170
+ {
171
+ EmailAddresses = new List < EmailAddress >
172
+ {
173
+ new EmailAddress
174
+ {
175
+
176
+ Location = "Work"
177
+ }
178
+ }
179
+ }
180
+ } ;
181
+
182
+ var xml = new XmlSerializer ( ) ;
183
+ var doc = xml . Serialize ( poco ) ;
184
+ var expected = GetSimplePocoXDocWackyNamesWithIListProperty ( ) ;
185
+
186
+ Assert . Equal ( expected . ToString ( ) , doc . ToString ( ) ) ;
187
+ }
188
+
160
189
[ Fact ]
161
190
public void Can_serialize_a_list_which_is_the_root_element ( )
162
191
{
@@ -238,12 +267,36 @@ private class WackyPerson
238
267
239
268
[ SerializeAs ( Name = "start_date" , Attribute = true ) ]
240
269
public DateTime StartDate { get ; set ; }
270
+
271
+ [ SerializeAs ( Name = "contact-data" ) ]
272
+ public ContactData ContactData { get ; set ; }
241
273
}
242
274
243
275
[ SerializeAs ( Name = "People" ) ]
244
276
private class PersonList : List < Person >
245
277
{
278
+
279
+ }
280
+
281
+ private class ContactData
282
+ {
283
+ public ContactData ( )
284
+ {
285
+ EmailAddresses = new List < EmailAddress > ( ) ;
286
+ }
287
+
288
+ [ SerializeAs ( Name = "email-addresses" ) ]
289
+ public List < EmailAddress > EmailAddresses { get ; set ; }
290
+ }
291
+
292
+ [ SerializeAs ( Name = "email-address" ) ]
293
+ private class EmailAddress
294
+ {
295
+ [ SerializeAs ( Name = "address" ) ]
296
+ public string Address { get ; set ; }
246
297
298
+ [ SerializeAs ( Name = "location" ) ]
299
+ public string Location { get ; set ; }
247
300
}
248
301
249
302
private XDocument GetSimplePocoXDoc ( )
@@ -323,6 +376,26 @@ private XDocument GetSimplePocoXDocWackyNames() {
323
376
return doc ;
324
377
}
325
378
379
+ private XDocument GetSimplePocoXDocWackyNamesWithIListProperty ( )
380
+ {
381
+ var doc = new XDocument ( ) ;
382
+ var root = new XElement ( "Person" ) ;
383
+ root . Add ( new XAttribute ( "WackyName" , "Foo" ) ,
384
+ new XElement ( "Age" , 50 ) ,
385
+ new XAttribute ( "Price" , 19.95m ) ,
386
+ new XAttribute ( "start_date" , new DateTime ( 2009 , 12 , 18 , 10 , 2 , 23 ) . ToString ( ) ) ,
387
+ new XElement ( "contact-data" ,
388
+ new XElement ( "email-addresses" ,
389
+ new XElement ( "email-address" ,
390
+ new XElement ( "address" , "[email protected] " ) ,
391
+ new XElement ( "location" , "Work" )
392
+ ) ) ) ) ;
393
+
394
+ doc . Add ( root ) ;
395
+
396
+ return doc ;
397
+ }
398
+
326
399
private XDocument GetSortedPropsXDoc ( ) {
327
400
var doc = new XDocument ( ) ;
328
401
var root = new XElement ( "OrderedProperties" ) ;
0 commit comments