Serializing Lists of Classes to XML

前端 未结 4 1966
清歌不尽
清歌不尽 2020-12-01 03:44

I have a collection of classes that I want to serialize out to an XML file. It looks something like this:

public class Foo
{
  public List BarList         


        
4条回答
  •  一个人的身影
    2020-12-01 04:25

    It has been over 5 years since this item was posted. I give my experience from July 2013 (.NET Framework 4.5). For what it's worth and to whom it may concern:

    When I define a class like so: (VB.Net code)

     Public Class MyClass
        Public Property Children as List(of ChildCLass)
         Public Property MyFirstProperty as string
         Public Property MySecondProperty as string
    End Class
    
     Public Class ChildClass
         Public Property MyFirstProperty as string
         Public Property MySecondProperty as string
    End Class
    

    With this definition the class is (de)serialized without any problems. This is the XML that comes out of here:

     MyFirstProperty="" MySecondProperty=""
        
             MyFirstProperty="" MySecondProperty=""
            
       
    
    

    It only took me two days to figure it out that the solution was to leave out the prefix of the List(of T) elements.

提交回复
热议问题