C#을 사용하여 SILVERLIGHT에서 직렬화를 시도하고 있습니다. 전에는 XmlArray를 사용하고 있었지만 작동 중이 었습니다. 대신 List를 사용하고 싶습니다. List를 사용하여 이전 파트를 모두 수행 했으므로 (배열을 사용할 때 이상하게 보입니다).List (배열 아님)를 사용하여이 xml을 deserialize하는 방법
내 XML은 같다 :
<ps>
<disable_others>
<disable_other>
<disable_value>1</disable_value>
<to_disable>skew</to_disable>
<to_disable>skew_side</to_disable>
</disable_other>
<disable_other>
<disable_value>0</disable_value>
<to_disable>automodel</to_disable>
</disable_other>
</disable_others>
<ps>
그리고 내 시도는이 역 직렬화 :
는[XmlRoot(ElementName = "ps")]
public class ps
{
[XmlArray("disable_others")]
[XmlArrayItem("disable_other", IsNullable = false)]
public List<string> Disable_Others { get; set; }
/* I know it can be done using the below but i have to use List not array:
[XmlArray("disable_others")]
[XmlArrayItem("disable_other", IsNullable = false)]
public Disable_Other[] Disable_Others { get; set; } */
}
[XmlRoot(ElementName = "disable_Others")]
public class Disable_Others
{
[XmlElement("disable_other")]
public List<Disable_Other> Disable_Other { get; set; }
}
[XmlRoot(ElementName = "Disable_Other")]
public class Disable_Other
{
[XmlElement("disablingitem")]
public int DisablingItem { get; set; }
[XmlElement("to_disable")]
public string[] To_Disable { get; set; }
[XmlElement("disable_value")]
public byte Disable_Value { get; set; }
}
은 어떤 사람이 나를 대신 배열 (XmlArray) 목록을 사용하여 목표를 달성하는 데 도움이 시겠어요?
배열에 대한 작업을 이미 수행 한 경우에는 ['Enumerable.ToList()'] (http://msdn.microsoft.com)을 사용할 수 없습니다. /en-us/library/vstudio/bb342261%28v=vs.100%29.aspx) 배열에? (또는 너무 비효율적입니까?) –
@MatthewWatson 아니요, 수동으로해야합니다. – Sss
u는 목록 필드와 함께 xmlarray ...를 사용할 수 있습니다. 클래스를 [serializable]로 표시해야합니다. – terrybozzio