我如何在另一个班级中填写一个班级的财产? [英] How can i fill a class prperty form another class?

查看:60
本文介绍了我如何在另一个班级中填写一个班级的财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类,其中有FreeDressingItems,FreeToppingItems,FreeInstructionItems的集合

I have class where i have the collection of FreeDressingItems, FreeToppingItems, FreeInstructionItems

都填充selectedCustomization我在此类public string Items { get { return GetAllItems(); } }

that is like this each of which fill selectedCustomization i have another property in this class public string Items { get { return GetAllItems(); } }

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

that i want to fill so that it keeps the all catetoryname for the same category type so that i can bind it to grid easily and display all its value in comma separated form.

我有以下代码可以帮助我如何实现这一目标.

i have following code could somebody help me how can i acineve this.

  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

this is another class 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的关系?

How can i make tiems of selectedCustomization in comma separated form?

推荐答案

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

I believe the method GetAllItems should be like below:

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());  
}

这将解决您的问题.

这篇关于我如何在另一个班级中填写一个班级的财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆