내 XML 파일에서 목록을 역 직렬화하는 데 문제가 있습니다. 내 속성은 내부이므로 xmlserializer가 아닌 datacontractserializer를 사용하고 있습니다.DataContractSerializer 및 일반 목록
<?xml version="1.0" encoding="utf-8" ?>
<Root xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Root">
<BackgroundColor>
0,0,255
</BackgroundColor>
<RowGap>1</RowGap>
<Table>
<TableHeading>"H1"</TableHeading>
<StartingColumn>A</StartingColumn>
</Table>
<Table>
<TableHeading>"H2"</TableHeading>
<StartingColumn>B</StartingColumn>
</Table>
</Root>
루트는 테이블의 목록을 가지고 다음과 같이
내 XML이다. ListOfTables는 deserialize되고 있지 않습니다. 클래스
[DataContract()]
public class Root
{
[OnDeserialized]
internal void OnSerializingMethod(StreamingContext context)
{
if (Table == null)
{
Table = new List<TableStructure>();
}
}
[DataMember(Name = "RowGap")]
internal int RowGap { get; set; }
[DataMember(Name = "TableHeaderBackgroundColor")]
internal string HdrBackColor { get; set; }
[DataMember()]
internal List<TableStructure> Table { get; set; }
}
[DataContract(Name = "Table", Namespace = "")]
public sealed class TableStructure
{
[DataMember]
public string TableHeading { get; set; }
[DataMember]
public string StartingColumn { get; set; }
}
desrialize 방법
internal static Root GetSettings()
{
Root settings;
using (FileStream fs = new FileStream("Root.xml", FileMode.Open, FileAccess.Read))
{
using (XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas()))
{
var x = new DataContractSerializer(typeof(Root));
settings = (Root)x.ReadObject(reader);
reader.Close();
fs.Close();
}
}
return settings;
}
이 오류없이 실행하지만, 모든 테이블 정보를로드하지 않습니다. RowGap 및 색상로드 중
당신의 도움에 감사드립니다. 이제 작동합니다. – MJK