0

我有课,我收集了 FreeDressingItems、FreeToppingItems、FreeInstructionItems

就像这样,每个都填充 selectedCustomization 我在这个类中有另一个属性 public string Items { get { return GetAllItems(); } }

我想填充它,以便它保留同一类别类型的所有类别名称,以便我可以轻松地将其绑定到网格并以逗号分隔的形式显示其所有值。

我有以下代码有人能帮我吗?

  public class selectedCustomization
    {
        public CategoryType TypeName { get; set; }
        public string CategoryName { get; set; }
        public string ItemName { get; set; }
        public int SourceID { get; set; }
        public string Items { get { return GetAllItems(); } }
        private string GetAllItems()
        {
            switch (TypeName)
            {
                    case CategoryType.Dressing:
                    {
                        cFreeCustomization cfreeCust = new cFreeCustomization();
                        break;
                     }


                case CategoryType.Topping:

                    break;

                case CategoryType.SpecialInstruction:

                    break;


            }

        }

    }

这是另一个类 cFreeCustomization

public List<selectedCustomization> SelectedItems
    {
        get
        {
            libDBDataContext cn = new libDBDataContext();
            List<selectedCustomization> lst = new List<selectedCustomization>();
            lst.AddRange(
                        (from xx in this.FreeDressingItems
                         select new selectedCustomization() { TypeName = CategoryType.Dressing, CategoryName = xx.DressingInfo.CatName, ItemName = xx.DressingInfo.Description }
                        ).ToList()
                        );
            lst.AddRange(
                        (from xx in this.FreeToppingItems
                         select new selectedCustomization() { TypeName = CategoryType.Topping, CategoryName = xx.ToppingInfo.CatName, ItemName = xx.ToppingInfo.Description }
                        ).ToList()
                        );
            lst.AddRange(
                        (from xx in this.FreeInstructionItems
                         select new selectedCustomization() { TypeName = CategoryType.SpecialInstruction, CategoryName = xx.InstructionInfo.CatName, ItemName = xx.InstructionInfo.Description }
                        ).ToList()
                        );
            return lst;
        }
    }

如何以逗号分隔的形式制作 selectedCustomization 的关系?

4

1 回答 1

1

我相信该方法GetAllItems应该如下所示:

private string GetAllItems()
{
    cFreeCustomization cfreeCust = new cFreeCustomization();
    var ls = cfreeCust.SelectedItems.FindAll(I => I.TypeName == this.TypeName);
    return string.Join(",", ls.Select(I => I.CategoryName).ToArray());  
}

这将解决您的问题。

于 2013-08-03T16:29:55.413 回答