Click here to Skip to main content
15,905,508 members
Home / Discussions / C#
   

C#

 
GeneralRe: Error in WebBrowser Pin
maylels16-Nov-06 12:27
maylels16-Nov-06 12:27 
QuestionWhich componenets to register in deployment projects Pin
wasife16-Nov-06 6:41
wasife16-Nov-06 6:41 
QuestionSelect a node in a treeView using Mouse Right Click Pin
h@s@n16-Nov-06 6:23
h@s@n16-Nov-06 6:23 
AnswerRe: Select a node in a treeView using Mouse Right Click Pin
Judah Gabriel Himango16-Nov-06 6:40
sponsorJudah Gabriel Himango16-Nov-06 6:40 
QuestionCOM interop threading problem Pin
Emad Attia16-Nov-06 5:53
Emad Attia16-Nov-06 5:53 
AnswerRe: COM interop threading problem Pin
Judah Gabriel Himango16-Nov-06 6:35
sponsorJudah Gabriel Himango16-Nov-06 6:35 
GeneralRe: COM interop threading problem Pin
Emad Attia16-Nov-06 6:55
Emad Attia16-Nov-06 6:55 
QuestionHow to run custom code when List.Add or List.Remove is running Pin
Chris Richner16-Nov-06 5:38
Chris Richner16-Nov-06 5:38 
Hi,

Before generics I used something like this to connect childs with parent classes

C#
interface IMyItem
{
      CollectionOwner Owner{get;set;}
}
class MyCollection : System.Collections.CollectionBase
{
    // ctor
    public MyCollection(CollectionOwner owner)
    {
         _owner = owner;
    }
    // internal interface
    protected override OnAdd(object item)
    {
        if(item is IMyItem) ((IMyItem)item).Owner = _owner;
    }
}

this way one was able to add items to a owner class owner.Items.Add(new Item()) and the owner had the item instance in his list while the item had a reference to his owner, which made a call like item.Remove() possible instead of calling owner.Items.Remove(item)

Now, .net 2.0 introduced generics, way cool. But how do I implement this behaviour with generics? There is no overrideable method instead of using the brute force method with new

C#
class MyCollection<T> : List<T>
where T : IMyItem

{
      // ctor
      MyCollection(CollectionOwner owner)
      {
             _owner = owner;
      }
      new public void Add(T item)
      {
            item.Owner = _owner;
            base.Add(item);
      }
}


this way if one is casting MyCollection back to List<> my custom add method isn't run. bad design

how can I extend generic collection base classes with such logic to do some extra work on each add or remove?

myMsg.BehindDaKeys = "Chris Richner";

AnswerRe: How to run custom code when List.Add or List.Remove is running Pin
Judah Gabriel Himango16-Nov-06 6:29
sponsorJudah Gabriel Himango16-Nov-06 6:29 
AnswerRe: How to run custom code when List.Add or List.Remove is running Pin
Daniel Grunwald16-Nov-06 7:43
Daniel Grunwald16-Nov-06 7:43 
AnswerRe: How to run custom code when List.Add or List.Remove is running Pin
Chris Richner16-Nov-06 8:49
Chris Richner16-Nov-06 8:49 
QuestionSending Email Message Pin
zaboboa16-Nov-06 5:33
zaboboa16-Nov-06 5:33 
AnswerRe: Sending Email Message Pin
ednrgc16-Nov-06 6:15
ednrgc16-Nov-06 6:15 
QuestionGetting default namespace name Pin
Zoltan Balazs16-Nov-06 5:08
Zoltan Balazs16-Nov-06 5:08 
AnswerRe: Getting default namespace name Pin
led mike16-Nov-06 5:26
led mike16-Nov-06 5:26 
GeneralRe: Getting default namespace name Pin
Zoltan Balazs16-Nov-06 7:15
Zoltan Balazs16-Nov-06 7:15 
AnswerRe: Getting default namespace name Pin
Daniel Grunwald16-Nov-06 7:44
Daniel Grunwald16-Nov-06 7:44 
GeneralRe: Getting default namespace name Pin
Zoltan Balazs16-Nov-06 8:32
Zoltan Balazs16-Nov-06 8:32 
QuestionPower Notation Pin
demetriou16-Nov-06 5:06
demetriou16-Nov-06 5:06 
AnswerRe: Power Notation Pin
User 665816-Nov-06 6:05
User 665816-Nov-06 6:05 
AnswerRe: Power Notation Pin
ednrgc16-Nov-06 6:28
ednrgc16-Nov-06 6:28 
Questiondataset Pin
fmardani16-Nov-06 4:26
fmardani16-Nov-06 4:26 
AnswerRe: dataset Pin
albCode16-Nov-06 4:32
albCode16-Nov-06 4:32 
AnswerRe: dataset Pin
Drew McGhie16-Nov-06 9:35
Drew McGhie16-Nov-06 9:35 
QuestionSockets overflowing? Pin
hammerstein0516-Nov-06 4:08
hammerstein0516-Nov-06 4:08 

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.