嵌套对象列表,最后一个列表无法访问?

时间:2013-06-14 20:05:39

标签: c# list nested

在下面的代码中,我尝试将AttributeValueInfoEntity添加到AttributeValueExportList,但是它没有显示为我放置ArticleAttributeExportLarge对象的属性//largeExportList.AttributeExportList 1}}在代码中。

我做错了什么,或者我在C#中错过了一个重要的嵌套规则?

public partial class Export_Articles_Default : System.Web.UI.Page
{       
    protected void Page_Load(object sender, EventArgs e)
    {
            ArticleInfoEntity[] articleInfoList = ArticleInfoFactory.Instance.ListInfo(244);
            List<ArticleExportLarge> list = new List<ArticleExportLarge>();

            foreach (ArticleInfoEntity aie in articleInfoList)
            {
                ArticleExportLarge largeExportList = new ArticleExportLarge(aie);
                largeExportList.AttributeExportList = new List<ArticleAttributeExportLarge>();

                List<AttributeInfoEntity> attributeInfoList = AttributeInfoFactory.Instance.ListByArticle(aie.ArticleId);


                foreach (AttributeInfoEntity attributeInfo in attributeInfoList)
                {
                    largeExportList.AttributeExportList.Add(new ArticleAttributeExportLarge(attributeInfo));
                    List<AttributeValueInfoEntity> ArticleValueInfoList = AttributeValueInfoFactory.Instance.ListByArticleAndAttribute(aie.ArticleId, attributeInfo.AttributeId);

                    foreach (AttributeValueInfoEntity avie in ArticleValueInfoList)
                    {
                       //largeExportList.AttributeExportList
                    }
                }

                list.Add(largeExportList);
            }   
        }
}

public class ArticleExportLarge
{
    private ArticleInfoEntity articleInfo;
    private List<ArticleAttributeExportLarge> attributeExportList;

    public ArticleExportLarge(ArticleInfoEntity articleInfo)
    {
        this.articleInfo = articleInfo;
    }

    [XmlElement(ElementName = "attributeList")]
    public List<ArticleAttributeExportLarge> AttributeExportList
    {
        get { return attributeExportList; }
        set { attributeExportList = value; }
    }

}

public class ArticleAttributeExportLarge
    {
        private AttributeInfoEntity attributeInfo;
        private List<ArticleAttributeValueExportLarge> attributeValueExportList;

        public ArticleAttributeExportLarge(AttributeInfoEntity attributeInfo)
        {
            this.attributeInfo = attributeInfo;
        }

        [XmlElement(ElementName = "attributeValueList")]
        public List<ArticleAttributeValueExportLarge> AttributeValueExportList
        {
            get { return attributeValueExportList; }
            set { attributeValueExportList = value; }
        }
    }

public class ArticleAttributeValueExportLarge
{
    private AttributeValueInfoEntity attributeValueExportEntity;

    public AttributeValueInfoEntity AttributeValueExportEntity
    {
        get { return attributeValueExportEntity; }
        set { this.attributeValueExportEntity = value; }
    }

}

1 个答案:

答案 0 :(得分:0)

我发现了我的错误。如果我想访问该列表中的对象,我需要遍历辅助列表largeExportList.AttributeExportList