开发者

Trouble getting a list of a custom class to serialize for user.config

开发者 https://www.devze.com 2023-01-11 16:01 出处:网络
I have the following classes [Serializable()] public class ColumnList { public ColumnList() { ListOfColumns = new List<Column>();

I have the following classes

[Serializable()]
public class ColumnList
{
    public ColumnList()
    {
        ListOfColumns = new List<Column>();
    }
    public ColumnList(string name) 
        : this()
    {
        Name = name;
    }

    List<Column> ListOfColumns { get; set;}
    public string Name { get; set; }
    //Extra methods cut out.
}
[Serializable()]
public partial class Column
{
    public Column()
    {
        VarName = "";
        HeaderName = "";
        ItemType = "";
        SelectText = "";
        Position = 0;
        Visable = true;
    }
    public Column(string varName, string headerName, string开发者_StackOverflow中文版 itemType, string selectText, int position)
    {
        VarName = varName;
        HeaderName = headerName;
        ItemType = itemType;
        SelectText = selectText;
        Position = position;
        Visable = true;
    }

    public string VarName { get; set; }
    public string HeaderName { get; set; }
    public string ItemType { get; set; }
    public string SelectText { get; set; }
    public int Position { get; set; }
    public bool Visable { get; set; }
    //extra methods cut out.
}

With the following in my Settings.cs file

[global::System.Configuration.UserScopedSettingAttribute()]
public List<ColumnList> ColumnListLists
{
    get { return ((List<ColumnList>)(this["ColumnListLists"])); }
    set { this["ColumnListLists"] = value; }
}

So basically I have a list of a class, that class contains a name and a list of another class. That class has a several strings, a boolean, and a int.

However after my program runs my user.config has this in it.

<value>
    <ArrayOfColumnList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <ColumnList>
            <Name>Preproduction</Name>
        </ColumnList>
        <ColumnList>
            <Name>Production</Name>
        </ColumnList>
        <ColumnList>
            <Name>Contract Approval</Name>
        </ColumnList>
    </ArrayOfColumnList>
</value>

It has the name of the ColumnList but it does not contain the Column elements. Any suggestions on what I am doing wrong?


Because...

List<Column> ListOfColumns { get; set;}

...is private, the XML serializer ignores it.

0

精彩评论

暂无评论...
验证码 换一张
取 消