8
のXMLシリアルIは、すべてこれまでのところ、同じクラス(MasterElement)C# - 派生クラス
public class XMLFile
{
[XmlArray("MasterFiles")]
public List<MasterElement> MasterFiles;
...
}
[XmlInclude(typeof(Supplier))]
[XmlInclude(typeof(Customer))]
public abstract class MasterElement
{
public MasterElement()
{
}
}
[XmlType(TypeName = "Supplier")]
public class Supplier: MasterElement
{
public string SupplierID;
public string AccountID;
}
[XmlType(TypeName = "Customer")]
public class Customer: MasterElement
{
public string CustomerID;
public string AccountID;
public string CustomerTaxID;
}
から派生する、複数の要素(サプライヤー、顧客、製品、など)の一覧をシリアル化しようとしていますXMLを解析しているが、現在の出力は
<MasterFiles>
<MasterElement xsi:type="Supplier">
<SupplierID>SUP-000001</SupplierID>
<AccountID>Unknown</AccountID>
</MasterElement>
<MasterElement xsi:type="Customer">
<CustomerID>CLI-000001</CustomerID>
<AccountID>Unknown</AccountID>
<CustomerTaxID>Unknown</CustomerTaxID>
</MasterElement>
</MasterFiles>
ですが、私がしたいことは何午前
<MasterFiles>
<Supplier>
<SupplierID>SUP-000001</SupplierID>
<AccountID>Unknown</AccountID>
</Supplier>
<Customer>
<CustomerID>CLI-000001</CustomerID>
<AccountID>Unknown</AccountID>
<CustomerTaxID>Unknown</CustomerTaxID>
</Customer>
</MasterFiles>
です私はここで間違っている?
public class XMLFile
{
[XmlArray("MasterFiles")]
[XmlArrayItem("Supplier", typeof(Supplier))]
[XmlArrayItem("Customer", typeof(Customer))]
public List<MasterElement> MasterFiles;
}
リンクMSDNから:
ありがとう、それは完全に働いた:) –