百分求解:Arraylist(其成员为int[])属性序列化的问题(在线急等)

yan63 2006-07-31 09:13:46
类:
public class someclass
{
private Arraylist _Array;

[XmlElement("elmName",typeof(int[]))]
public ArrayList SomeArray
{
get
{
return _Array;
}
}

public someclass()
{}

.......
}

实例化:
someclass sample = new someclass()
sample .SomeArray.Add(new int[1]{2});
......
序列化:
StreamWriter writer = new StreamWriter(filePath,false,Encoding.UTF8);
XmlSerializer mySerializer = new XmlSerializer(typeof(someclass));
try
{
mySerializer.Serialize(writer, this);
}
catch (Exception ex)
{
throw ex;
}
finally
{
writer.Close();
}

错误信息:
未处理的“System.InvalidOperationException”类型的异常出现在 system.xml.dll 中。

其他信息: 无法生成临时类(result=1)。
error CS0030: 无法将类型“System.Collections.ArrayList”转换为“int[]”
error CS0029: 无法将类型“int[]”隐式转换为“System.Collections.ArrayList”
...全文
369 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dlzhangln 2006-07-31
  • 打赏
  • 举报
回复
jf
jc15271149 2006-07-31
  • 打赏
  • 举报
回复
jf
yan63 2006-07-31
  • 打赏
  • 举报
回复
散分罗...24小时内有效
yan63 2006-07-31
  • 打赏
  • 举报
回复
需要XmlArray 与XmlArrayItem组合使用

[XmlArray ("nonClusteredKey")]
[XmlArrayItem("keys",typeof(int[]))]
public ArrayList SomeArray
{
get
{
return m__Array;
}
set
{
m__Array= value;
}
}

shanfree 2006-07-31
  • 打赏
  • 举报
回复
我是楼主,
真是faint,自己找了个临时的解决办法
[XmlArrayItem("keys",typeof(int[]))]
public ArrayList SomeArray
{
get
{
return m__Array;
}
set
{
m__Array= value;
}
}

xml输出:
......
<SomeArray>
<keys>
<int>2</int>
</keys>
</SomeArray>
......
属性名称SomeArray无法修改,请问谁有更好的解决方法,24小时后揭帖,帮顶也给分
yan63 2006-07-31
  • 打赏
  • 举报
回复
兄弟姐妹们呐,在下叩谢了...

110,549

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧