获取要为 user.config 序列化的自定义类列表时遇到问题
我有以下类
[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为...
...是私有的,所以 XML 序列化程序会忽略它。
Because...
...is private, the XML serializer ignores it.