首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用匿名数据类型编译XDocument

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

Stack Overflow用户
提问于 2016-02-25 07:01:12
回答 1查看 31关注 0票数 0

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

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

我的玻璃钢是list>玻璃钢

代码语言:javascript
复制
        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

我的预期输出如下所示

代码语言:javascript
复制
    <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>

从我的谷歌,我知道我需要命名的类型,但我真的不知道这意味着什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-25 07:32:16

使用一个类似于此的对象图-

代码语言:javascript
复制
[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对象。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35620468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档