Pola publiczne / właściwości klasy pochodzącej z BindingList <T> nie będą serializowane

Próbuję serializować klasę, z której pochodziBindingList (piętro), gdziePodłoga to prosta klasa, która zawiera tylko właściwośćFloor.Height

Oto uproszczona wersja mojej klasy

[Serializable]
[XmlRoot(ElementName = "CustomBindingList")]
public class CustomBindingList:BindingList<Floor>
{
    [XmlAttribute("publicField")]
    public string publicField;
    private string privateField;

    [XmlAttribute("PublicProperty")]
    public string PublicProperty
    {
        get { return privateField; }
        set { privateField = value; }
    }
}

Serializuję instancję CustomBindingList przy użyciu następującego kodu.

XmlSerializer ser = new XmlSerializer(typeof(CustomBindingList));
StringWriter sw = new StringWriter();

CustomBindingList cLIst = new CustomBindingList();

Floor fl;

fl = new Floor();
fl.Height = 10;
cLIst.Add(fl);

fl = new Floor();
fl.Height = 10;    
cLIst.Add(fl);

fl = new Floor();
fl.Height = 10;
cLIst.Add(fl);

ser.Serialize(sw, cLIst);

string testString = sw.ToString();

JeszczetestString powyżej kończy się ustawieniem na następujący XML:

<CustomBindingList xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">
    <Floor Height="10" />
    <Floor Height="10" />
    <Floor Height="10" />
</CustomBindingList>"

Jak uzyskać „publicField” lub „publicProperty, aby również serializować?

questionAnswers(3)

yourAnswerToTheQuestion