我有以下代码,它抛出了以下错误:
“无效的匿名类型成员声明器。必须声明匿名类型成员.”
我的玻璃钢是list>玻璃钢
var grp = lstCuts.GroupBy(x =>` x.Bar_id).Select(a=>a.ToList()).ToList();
foreach(var bar in grp)
{
XElement bardata = new XElement("BAR",
new XElement("BRAN", bar[0].Brand),
new XElement("SYST", bar[0].System),
new XElement("CODE", bar[0].Code),
new XElement("DESC", bar[0].Description),
new XElement("DICL", bar[0].DICL),
new XElement("DOCL", bar[0].DOCL),
new XElement("LEN", bar[0].Length),
new XElement("STS", bar[0].BarStatus),
new XElement("H", bar[0].H),
new XElement("MLT", "1"),
new XElement("CUT",
from a in bar
select XElement(new
{
new XElement("ANGL", a.AngleL.ToString()),
new XElement("ANGL",)
new XElement("ANGL",)
new XElement("ANGL",)
new XElement("ANGL",)
new XElement("ANGL",)
new XElement("ANGL",)
new XElement("ANGL",)
new XElement("ANGL",)
new XElement("ANGL",)
})
//create a new bar and add all the cuts我的预期输出如下所示
<BAR>
<BRAN>ALSPEC</BRAN>
<SYST>McArthur 101.6mm Centre Pocket</SYST>
<CODE>AS1C</CODE>
<DESC>Main Frame - Captive</DESC>
<DICL>ANOGRP3</DICL>
<DOCL>25um Anodised</DOCL>
<LEN>6500</LEN>
<STS>1</STS>
<H>101.6</H>
<MLT>1</MLT>
<CUT>
<NUM>1</NUM>
<TYPE />
<ANGL>90</ANGL>
<ANGR>90</ANGR>
<AB1>90</AB1>
<AB2>90</AB2>
<IL>5816</IL>
<OL>5816</OL>
<BCOD>0000000475/1/4</BCOD>
<DESC>Jamb - Right</DESC>
<STAT>1</STAT>
<LBL>Job#878/Item#1</LBL>
<LBL>5816 mm</LBL>
<LBL>DW1</LBL>
<LBL>Jamb - Right</LBL>
</CUT>
<CUT>
<NUM>1</NUM>
<TYPE />
<ANGL>90</ANGL>
<ANGR>90</ANGR>
<AB1>90</AB1>
<AB2>90</AB2>
<IL>5816</IL>
<OL>5816</OL>
<BCOD>0000000475/1/4</BCOD>
<DESC>Jamb - Right</DESC>
<STAT>1</STAT>
<LBL>Job#878/Item#1</LBL>
<LBL>5816 mm</LBL>
<LBL>DW1</LBL>
<LBL>Jamb - Right</LBL>
</CUT>
<CUT>
<NUM>1</NUM>
<TYPE />
<ANGL>90</ANGL>
<ANGR>90</ANGR>
<AB1>90</AB1>
<AB2>90</AB2>
<IL>5816</IL>
<OL>5816</OL>
<BCOD>0000000475/1/4</BCOD>
<DESC>Jamb - Right</DESC>
<STAT>1</STAT>
<LBL>Job#878/Item#1</LBL>
<LBL>5816 mm</LBL>
<LBL>DW1</LBL>
<LBL>Jamb - Right</LBL>
</CUT>
</BAR>从我的谷歌,我知道我需要命名的类型,但我真的不知道这意味着什么。
发布于 2016-02-25 07:32:16
使用一个类似于此的对象图-
[XmlRoot(ElementName = "BAR")]
public class Bar
{
public string BRAN { get; set; }
public string SYST { get; set; }
public string CODE { get; set; }
public string DESC { get; set; }
public string DICL { get; set; }
public string DOCL { get; set; }
public string LEN { get; set; }
public string STS { get; set; }
public string H { get; set; }
public string MLT { get; set; }
public List<Cut> Cuts { get; set; }
}
[XmlRoot(ElementName = "CUT")]
public class Cut
{
public string NUM { get; set; }
public string TYPE { get; set; }
public string ANGL { get; set; }
public string ANGR { get; set; }
public string AB1 { get; set; }
public string AB2 { get; set; }
public string IL { get; set; }
public string OL { get; set; }
public string BCOD { get; set; }
public string DESC { get; set; }
public string STAT { get; set; }
public LBL LBL { get; set; }
}
public class LBL
{
[XmlArrayItem(ElementName = "LBL")]
public List<string> Lbl { get; set; }
}然后使用一个Bar序列化XmlSerializer对象。
https://stackoverflow.com/questions/35620468
复制相似问题