2013-08-03 98 views
0

我有類在那裏我有FreeDressingItems,FreeToppingItems收集,FreeInstructionItems我怎樣才能填寫另一個班的班級屬性?

就是這個樣子的每一個填補selectedCustomization我還有一個屬性在這個類public string Items { get { return GetAllItems(); } }

,我想,以填補,使其保持相同類別類型的所有catetoryname,以便我可以將其綁定到網格,並以逗號分隔的形式顯示其所有值。

我有以下代碼可以有人幫助我我怎麼能這樣做。

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的TIEMS?

+1

如果您的財產正在幕後調用方法,則只需刪除該財產併爲相同的目的創建一個方法。 – Icarus

+0

那麼我該如何訪問該集合? – NoviceToDotNet

+0

你能給我一些想法,我長時間工作嗎? – NoviceToDotNet

回答

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

這將解決您的問題。

+0

好吧讓我檢查它 – NoviceToDotNet

+0

但它重新instaniate整個對象和集合爲null總是。 – NoviceToDotNet

+0

FreeDressingItems count 0 – NoviceToDotNet

相關問題