Próbuję deserializowania następujące XML:deserializacji XML zwraca null dla właściwości zbierania
<?xml version="1.0" encoding="utf-8" ?>
<mf:somedata xmlns:mf="urn:somedata">
<CurrentAccount>
<AccountType>test</AccountType>
<Charge>
<ChargeType>test</ChargeType>
</Charge>
</CurrentAccount>
<CurrentAccount>
<AccountType>test 2</AccountType>
<Charge>
<ChargeType>test 2</ChargeType>
</Charge>
</CurrentAccount>
</mf:somedata>
Korzystanie z następujących klas:
[XmlRoot("somedata", Namespace = "urn:somedata")]
public class MfCurrentAccounts
{
[XmlElement("CurrentAccount")]
public CurrentAccount[] CurrentAccounts { get; set; }
}
public class CurrentAccount
{
public string AccountType { get; set; }
[XmlElement("Charge")]
public Charge[] Charges { get; set; }
}
public class Charge
{
public string ChargeType { get; set; }
}
var c = new XmlSerializer(typeof(MfCurrentAccounts)).Deserialize(new StringReader(xml)) as MfCurrentAccounts;
c.CurrentAccounts // <-- is always null
ale bez względu na to, co staram, jest tablica CurrentAccounts null, gdy deserializuję to. Próbowałem każdej kombinacji, którą mogę wymyślić z atrybutami (wypróbowałem XmlArray i XmlArrayItem też).
Co robię źle? : S
Przepraszamy, zaktualizowano pytanie za pomocą kodu deserializacji. – Tom
Czy nie ma potrzeby oznaczania klas za pomocą "[Serializable()]"? – Nope
@ François Próbowałem tego, ale najwyraźniej to nie jest potrzebne. – Tom