간단한에서 주문을 받아서 내가 필요한 것은 정의에 클래스 프로젝트는 부분적으로 XML 직렬화가 부분적으로
public class project : IXmlSerializable
{
[XmlAttribute]
public string name;
[XmlIgnore]
public string[] contents;
public XmlSchema GetSchema()
{
return null;
}
public void ReadXml(XmlReader reader)
{
if (reader.HasAttributes)
{
contents=new string[reader.AttributeCount];
for (int i = 0; i < reader.AttributeCount; i++)
{
reader.MoveToAttribute(i);
string attr = reader.Name;
Regex reg = new Regex(@"content_\d+");
if (reg.IsMatch(attr))
{
contents[i] = reader.Value;
}
}
}
}
public void WriteXml(XmlWriter writer)
{
for (int i = 0; i < contents.Count(); i++)
{
writer.WriteAttributeString("content_" + i, contents[i]);
}
}
}
내가 이름은 일반적으로 직렬화 할 수 있지만, 사용자 정의 배열의 내용 만이 (내가 속성으로해야 할 것입니다 프로젝트 노드에서). 실제로 어떤 일이 일어나는가는 프로젝트 클래스를 구현할 때 이름이 null로 유지되는 이유는 무엇이라고 생각합니까?
I * 강력하게 * IXmlSerializable 구현을 권장하지 않습니다. * 많은 사람들이 * 완전 혼란을 겪었습니다 ... 소비자에게 친숙하지 않습니다. –
큰 재귀 클래스를 직렬화하고 싶지만 사용자 정의 방식을 사용하면 좋은 방법입니다. – Miral
그 시나리오가 있다면 아마 XmlSerilaizer (또는 xml) *를 사용해서는 안된다고 말할 것입니다. first place * –