S Lemen

S Lemen

  • NA
  • 7
  • 15.8k

Custom Class Constructor of an Inherited List

Dec 24 2010 12:59 PM

HI,
    I have a class that inherits a List<T>, where T the a custom class far below.  The problem is creating the underlying list in the inheriting class constructor.  The inheriting class is immediately below.  How do I create the PerfAll List<PerfCategory> in the PerfAll constructor?
Thank you,
Scott
public class PerfAll : List<PerfCategory>
{
      private PerfAll _PerfAllCatCounters;

      public PerfAll()
      {
         _PerfAllCatCounters =
new List<PerfCategory>(); // <-- this line is a compiler error
         PerfAll _All;
         PerfCategory _PerfCat;
         PerformanceCounterCategory[] _CounterCategories =  PerformanceCounterCategory.GetCategories();
         foreach (PerformanceCounterCategory cat in _CounterCategories)
         {
            _PerfCat =
new PerfCategory(cat.CategoryName);
            _All.Add(_PerfCat);
         }
      _PerfAllCatCounters = _All;
   }
   public PerfAll PerformanceAllCatCounters
   {
      get
      {
            return _PerfAllCatCounters;
      }
   }
}

 
 
 
Custom class:
public class PerfCategory
{
   private string _CategoryName;
   private List<PerformanceCounter> _CounterList;
   public PerfCategory()
   {
      _CategoryName =
string.Empty;
      _CounterList =
new List<PerformanceCounter>();
   }
   public PerfCategory(string CategoryName)
      :
this()
   {
      PerformanceCounter[] _CounterArray;
      _CategoryName = CategoryName;
      PerformanceCounterCategory _Counter = new PerformanceCounterCategory(CategoryName);
      _CounterArray = _Counter.GetCounters();

      foreach (PerformanceCounter counters in _CounterArray)
      {
         _CounterList.Add(counters);
      }

   }
   public string CategoryName
   {
      get
      {
         return _CategoryName;
      }
      set
      {
         _CategoryName =
value;
      }
   }
   public List<PerformanceCounter> CounterList
   {
      get
      {
         return _CounterList;
      }
   }
}

Answers (2)