我有一个数据结构如下
class BasketCondition
{
public List<Sku> SkuList { get; set; }
public string InnerBoolean { get; set; }
}
class Sku
{
public string SkuName { get; set; }
public int Quantity { get; set; }
public int PurchaseType { get; set; }
}
现在让我们为其填充一些值
var skuList = new List<Sku>();
skuList.Add(new Sku { SkuName = "TSBECE-AA", Quantity = 2, PurchaseType = 3 });
skuList.Add(new Sku { SkuName = "TSEECE-AA", Quantity = 5, PurchaseType = 3 });
BasketCondition bc = new BasketCondition();
bc.InnerBoolean = "OR";
bc.SkuList = skuList;
愿望输出是
<BasketCondition>
<InnerBoolean Type="OR">
<SKUs Sku="TSBECE-AA" Quantity="2" PurchaseType="3"/>
<SKUs Sku="TSEECE-AA" Quantity="5" PurchaseType="3"/>
</InnerBoolean>
</BasketCondition>
到目前为止我的程序是
XDocument doc =
new XDocument(
new XElement("BasketCondition",
new XElement("InnerBoolean", new XAttribute("Type", bc.InnerBoolean),
bc.SkuList.Select(x => new XElement("SKUs", new XAttribute("Sku", x.SkuName)))
)));
这给了我输出
<BasketCondition>
<InnerBoolean Type="OR">
<SKUs Sku="TSBECE-AA" />
<SKUs Sku="TSEECE-AA" />
</InnerBoolean>
</BasketCondition>
如何将其余属性Quantity 和 PurchaseType添加到我的程序中。
请帮忙