获取要为 user.config 序列化的自定义类列表时遇到问题

发布于 2024-09-14 22:57:04 字数 2168 浏览 2 评论 0原文

我有以下类

[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 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.
}

在我的 Settings.cs 文件中有以下内容

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

所以基本上我有一个类的列表,该类包含另一个类的名称和列表。该类有几个字符串、一个布尔值和一个整数。

但是,在我的程序运行后,我的 user.config 中有这个。

<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>

它具有 ColumnList 的名称,但不包含 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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

硪扪都還晓 2024-09-21 22:57:04

因为...

List<Column> ListOfColumns { get; set;}

...是私有的,所以 XML 序列化程序会忽略它。

Because...

List<Column> ListOfColumns { get; set;}

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文