Click here to Skip to main content
16,005,080 members
Home / Discussions / C#
   

C#

 
AnswerRe: what means Error: "No mapping exists from object type System.Windows.Forms.TextBox to a known managed provider native type." Pin
Guffa22-May-07 0:46
Guffa22-May-07 0:46 
GeneralRe: what means Error: "No mapping exists from object type System.Windows.Forms.TextBox to a known managed provider native type." Pin
Member 814227811-Feb-12 4:52
Member 814227811-Feb-12 4:52 
QuestionSortable CollectionBase ? Pin
Gavin Roberts22-May-07 0:36
Gavin Roberts22-May-07 0:36 
AnswerRe: Sortable CollectionBase ? Pin
Pete O'Hanlon22-May-07 1:02
mvePete O'Hanlon22-May-07 1:02 
GeneralRe: Sortable CollectionBase ? Pin
Gavin Roberts22-May-07 1:59
Gavin Roberts22-May-07 1:59 
GeneralRe: Sortable CollectionBase ? Pin
Pete O'Hanlon22-May-07 4:01
mvePete O'Hanlon22-May-07 4:01 
GeneralRe: Sortable CollectionBase ? [modified] Pin
Gavin Roberts22-May-07 22:33
Gavin Roberts22-May-07 22:33 
GeneralRe: Sortable CollectionBase ? Pin
Pete O'Hanlon23-May-07 8:47
mvePete O'Hanlon23-May-07 8:47 
You've become slightly mixed up in what you need the interface to be. When a generic states where T : ... you are indicating that the type T will implement the interface. Also, you have used a generic list and then hardcoded the type in the iterator. To be honest, you possibly don't need to expose your class as generic because you have a specific non-generic need here. What you could do is declare a List<...> member as a private member and then use your own methods to add to it. If you definitely want to go the generic route here, this is a sample that I have just knocked up.
using System;
using System.Collections.Generic;
using System.Text;

namespace TestIterator
{
  class Program
  {
    static void Main(string[] args)
    {
      RequestItemCollection<Request> coll = new RequestItemCollection<Request>();
      Request req = new Request();
      req.Status = RequestStatus.Open;
      coll.Add(req);
      req = new Request();
      req.Status = RequestStatus.Open;
      coll.Add(req);
      System.Console.WriteLine("Open count = {0}", coll.OpenCount);
      Console.ReadLine();
    }
  }

  public class RequestItemCollection<T> : List<T>, IEnumerable<T> where T: IStatus
  {
    #region IEnumerable<T> Members

    IEnumerator<T> IEnumerable<T>.GetEnumerator()
    {
      for (int i = 0; i < this.Count; i++)
        yield return this[i];
    }

    #endregion

    #region IEnumerable Members

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
      throw new Exception("The method or operation is not implemented.");
    }

    #endregion

    public int OpenCount
    {
      get
      {
        return StatusCount(RequestStatus.Open);
      }
    }

    public int Closed
    {
      get
      {
        return StatusCount(RequestStatus.Closed);
      }
    }

    private int StatusCount(RequestStatus status)
    {
      int count = 0;

      foreach (T item in this)
      {
        if (item.Status == status)
          count++;
      }
      return count;
    }
  }

  public enum RequestStatus
  {
    Open,
    Closed,
    Pending
  }
  public interface IStatus
  {
    RequestStatus Status { get; set; }
  }

  public class Request : IStatus
  {
    private RequestStatus _status;
    #region IStatus Members

    public RequestStatus Status
    {
      get
      {
        return _status;
      }
      set
      {
        _status = value;
      }
    }

    #endregion
  }
}


Deja View - the feeling that you've seen this post before.

AnswerRe: Sortable CollectionBase ? Pin
Martin#22-May-07 1:29
Martin#22-May-07 1:29 
QuestionI want some source code for converting a 3GPP file to JPEG or GIF file Pin
Luna-Bangalore22-May-07 0:09
Luna-Bangalore22-May-07 0:09 
QuestionChanging print page settings Pin
Gareth H21-May-07 23:55
Gareth H21-May-07 23:55 
AnswerRe: Changing print page settings Pin
Gareth H22-May-07 21:28
Gareth H22-May-07 21:28 
QuestionNew line character in XML? Pin
chand1021-May-07 23:39
chand1021-May-07 23:39 
AnswerRe: New line character in XML? Pin
andre_swnpl22-May-07 1:13
andre_swnpl22-May-07 1:13 
QuestionAvi video Pin
Henrix5521-May-07 23:26
Henrix5521-May-07 23:26 
AnswerRe: Avi video Pin
Christian Graus22-May-07 0:32
protectorChristian Graus22-May-07 0:32 
GeneralRe: Avi video Pin
Henrix5522-May-07 0:49
Henrix5522-May-07 0:49 
QuestionOracle client installed? Pin
User 269896721-May-07 23:03
User 269896721-May-07 23:03 
AnswerRe: Oracle client installed? Pin
Gareth H21-May-07 23:24
Gareth H21-May-07 23:24 
GeneralRe: Oracle client installed? Pin
User 269896722-May-07 0:46
User 269896722-May-07 0:46 
QuestionRe: Oracle client installed? Pin
User 269896723-May-07 2:03
User 269896723-May-07 2:03 
QuestionInstall Database into MSQL Server by C# code ? [modified] Pin
AlienPham21-May-07 22:21
AlienPham21-May-07 22:21 
AnswerRe: Install Database into MSQL Server by C# code ? Pin
blackjack215021-May-07 23:18
blackjack215021-May-07 23:18 
GeneralRe: Install Database into MSQL Server by C# code ? Pin
Giorgi Dalakishvili21-May-07 23:24
mentorGiorgi Dalakishvili21-May-07 23:24 
Questionhow do achieve auto-login like msn messager Pin
jason_mf21-May-07 21:51
jason_mf21-May-07 21:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.