Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 使用匿名数据类型编译XDocument_Xml_Linq_Anonymous Types - Fatal编程技术网

Xml 使用匿名数据类型编译XDocument

Xml 使用匿名数据类型编译XDocument,xml,linq,anonymous-types,Xml,Linq,Anonymous Types,我有以下代码,它抛出以下错误: “无效的匿名类型成员声明符。必须声明匿名类型成员…” 我的grp是一个列表>grp var grp = lstCuts.GroupBy(x =>` x.Bar_id).Select(a=>a.ToList()).ToList(); foreach(var bar in grp) { XElement bardata = new XElement("BAR",

我有以下代码,它抛出以下错误:

“无效的匿名类型成员声明符。必须声明匿名类型成员…”

我的grp是一个列表>grp

        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>

通过我的谷歌搜索,我知道我需要以某种方式命名类型,但我不确定这意味着什么。

使用类似于此的对象图-

[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; }
}
[XmlRoot(ElementName=“BAR”)]
公共类酒吧
{
公共字符串{get;set;}
公共字符串系统{get;set;}
公共字符串代码{get;set;}
公共字符串DESC{get;set;}
公共字符串DICL{get;set;}
公共字符串DOCL{get;set;}
公共字符串LEN{get;set;}
公共字符串STS{get;set;}
公共字符串H{get;set;}
公共字符串MLT{get;set;}
公共列表剪切{get;set;}
}
[XmlRoot(ElementName=“CUT”)]
公共课削减
{
公共字符串NUM{get;set;}
公共字符串类型{get;set;}
公共字符串ANGL{get;set;}
公共字符串ANGR{get;set;}
公共字符串AB1{get;set;}
公共字符串AB2{get;set;}
公共字符串IL{get;set;}
公共字符串OL{get;set;}
公共字符串BCOD{get;set;}
公共字符串DESC{get;set;}
公共字符串STAT{get;set;}
公共LBL LBL{get;set;}
}
公共类LBL
{
[XmlArrayItem(ElementName=“LBL”)]
公共列表Lbl{get;set;}
}

然后使用
XmlSerializer

对象进行序列化,您好,谢谢您的回复!我最终实现了我想要的目标,每次都有几句话。我更喜欢你的方式,所以我明天试一试。谢谢意志