473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

CollectionBase bug?

Hi all,

I've been using the CollectionBase class to implement a
strongly-typed collection, but I have noticed that the
RemoveAt method does not seem to call the "On" hook
methods (OnRemove, OnRemoveComplete). The Add method works
fine, though! I need these to work -- I am exposing the
collection to the user through a PropertyGrid control, and
the user can add/remove collection elements with the
(apparently undocumented) Object Collection Editor that
the PropertyGrid invokes, and I need to do some work when
that happens...

Is this a bug? I saw a reference to the problem here:

http://lists.ximian.com/archives/public/mono-list/2001-
November/001978.html

Any thoughts?

Thanks, MP
Jul 21 '05 #1
7 1838
m. pollack wrote:
Hi all,

I've been using the CollectionBase class to implement a
strongly-typed collection, but I have noticed that the
RemoveAt method does not seem to call the "On" hook
methods (OnRemove, OnRemoveComplete). The Add method works
fine, though! I need these to work -- I am exposing the
collection to the user through a PropertyGrid control, and
the user can add/remove collection elements with the
(apparently undocumented) Object Collection Editor that
the PropertyGrid invokes, and I need to do some work when
that happens...
Can you not override the RemoveAt method ? If the RemoveAt method calls the
IList::Remove method, your implementation of that will catch the remove.

Is this a bug? I saw a reference to the problem here:

http://lists.ximian.com/archives/public/mono-list/2001-
November/001978.html

Any thoughts?

Jul 21 '05 #2
JD
Are you positive? I looked at the IL for the CollectionBase::RemoveAt and
the two statements do exist in the method call. Look below:

..method public hidebysig newslot virtual final
instance void RemoveAt(int32 index) cil managed
{
// Code size 83 (0x53)
.maxstack 3
.locals (object V_0)
IL_0000: ldarg.1
IL_0001: ldc.i4.0
IL_0002: blt.s IL_0012
IL_0004: ldarg.1
IL_0005: ldarg.0
IL_0006: call instance class System.Collections.ArrayList
System.Collections.CollectionBase::get_InnerList()
IL_000b: callvirt instance int32
System.Collections.ArrayList::get_Count()
IL_0010: blt.s IL_0022
IL_0012: ldstr "ArgumentOutOfRange_Index"
IL_0017: call string System.Environment::GetResourceString(string)
IL_001c: newobj instance void
System.ArgumentOutOfRangeException::.ctor(string)
IL_0021: throw
IL_0022: ldarg.0
IL_0023: call instance class System.Collections.ArrayList
System.Collections.CollectionBase::get_InnerList()
IL_0028: ldarg.1
IL_0029: callvirt instance object
System.Collections.ArrayList::get_Item(int32)
IL_002e: stloc.0
IL_002f: ldarg.0
IL_0030: ldloc.0
IL_0031: callvirt instance void
System.Collections.CollectionBase::OnValidate(obje ct)
IL_0036: ldarg.0
IL_0037: ldarg.1
IL_0038: ldloc.0
IL_0039: callvirt instance void
System.Collections.CollectionBase::OnRemove(int32,

object)
IL_003e: ldarg.0
IL_003f: call instance class System.Collections.ArrayList
System.Collections.CollectionBase::get_InnerList()
IL_0044: ldarg.1
IL_0045: callvirt instance void
System.Collections.ArrayList::RemoveAt(int32)
IL_004a: ldarg.0
IL_004b: ldarg.1
IL_004c: ldloc.0
IL_004d: callvirt instance void
System.Collections.CollectionBase::OnRemoveComplet e(int32,

object)
IL_0052: ret
} // end of method CollectionBase::RemoveAt
"m. pollack" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
Hi all,

I've been using the CollectionBase class to implement a
strongly-typed collection, but I have noticed that the
RemoveAt method does not seem to call the "On" hook
methods (OnRemove, OnRemoveComplete). The Add method works
fine, though! I need these to work -- I am exposing the
collection to the user through a PropertyGrid control, and
the user can add/remove collection elements with the
(apparently undocumented) Object Collection Editor that
the PropertyGrid invokes, and I need to do some work when
that happens...

Is this a bug? I saw a reference to the problem here:

http://lists.ximian.com/archives/public/mono-list/2001-
November/001978.html

Any thoughts?

Thanks, MP

Jul 21 '05 #3
The link you gave showed a problem where the On* methods were not called
when referencing the InnerList.

From the MSDN documention:
\\\
The On* methods are invoked only on the instance returned by the List
property, but not on the instance returned by the InnerList property.
///

OnRemove and OnRemoveComplete do work at Runtime, but do not appear to work
at DesignTime.
What does appear to happen though, is the Collection Editor clears and
creates a new List whenever you add or remove items from the List. I've not
got an answer as yet, but I'll also need it shortly.

"m. pollack" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
Hi all,

I've been using the CollectionBase class to implement a
strongly-typed collection, but I have noticed that the
RemoveAt method does not seem to call the "On" hook
methods (OnRemove, OnRemoveComplete). The Add method works
fine, though! I need these to work -- I am exposing the
collection to the user through a PropertyGrid control, and
the user can add/remove collection elements with the
(apparently undocumented) Object Collection Editor that
the PropertyGrid invokes, and I need to do some work when
that happens...

Is this a bug? I saw a reference to the problem here:

http://lists.ximian.com/archives/public/mono-list/2001-
November/001978.html

Any thoughts?

Thanks, MP

Jul 21 '05 #4
Thanks, Mick - I'd be very interested to know what you
come up with... M

-----Original Message-----
The link you gave showed a problem where the On* methods were not calledwhen referencing the InnerList.

From the MSDN documention:
\\\
The On* methods are invoked only on the instance returned by the Listproperty, but not on the instance returned by the InnerList property.///

OnRemove and OnRemoveComplete do work at Runtime, but do not appear to workat DesignTime.
What does appear to happen though, is the Collection Editor clears andcreates a new List whenever you add or remove items from the List. I've notgot an answer as yet, but I'll also need it shortly.

"m. pollack" <an*******@discussions.microsoft.com> wrote in messagenews:04****************************@phx.gbl...
Hi all,

I've been using the CollectionBase class to implement a
strongly-typed collection, but I have noticed that the
RemoveAt method does not seem to call the "On" hook
methods (OnRemove, OnRemoveComplete). The Add method works fine, though! I need these to work -- I am exposing the
collection to the user through a PropertyGrid control, and the user can add/remove collection elements with the
(apparently undocumented) Object Collection Editor that
the PropertyGrid invokes, and I need to do some work when that happens...

Is this a bug? I saw a reference to the problem here:

http://lists.ximian.com/archives/public/mono-list/2001-
November/001978.html

Any thoughts?

Thanks, MP

.

Jul 21 '05 #5
Thanks, Ed - this did not solve the problem, though. It
seems that the Collection Editor bypasses these methods
altogether when removing items...

MP
-----Original Message-----
m. pollack wrote:
Hi all,

I've been using the CollectionBase class to implement a
strongly-typed collection, but I have noticed that the
RemoveAt method does not seem to call the "On" hook
methods (OnRemove, OnRemoveComplete). The Add method works fine, though! I need these to work -- I am exposing the
collection to the user through a PropertyGrid control, and the user can add/remove collection elements with the
(apparently undocumented) Object Collection Editor that
the PropertyGrid invokes, and I need to do some work when that happens...
Can you not override the RemoveAt method ? If the

RemoveAt method calls theIList::Remove method, your implementation of that will catch the remove.

Is this a bug? I saw a reference to the problem here:

http://lists.ximian.com/archives/public/mono-list/2001-
November/001978.html

Any thoughts?

.

Jul 21 '05 #6
Thanks, JD, for looking at that.

I think the problem might be that the Collection Editor
destroys the old list and creates a new one when removing
items, so that the RemoveAt method never gets called.

MP
-----Original Message-----
Are you positive? I looked at the IL for the CollectionBase::RemoveAt andthe two statements do exist in the method call. Look below:
..method public hidebysig newslot virtual final
instance void RemoveAt(int32 index) cil managed
{
// Code size 83 (0x53)
.maxstack 3
.locals (object V_0)
IL_0000: ldarg.1
IL_0001: ldc.i4.0
IL_0002: blt.s IL_0012
IL_0004: ldarg.1
IL_0005: ldarg.0
IL_0006: call instance class System.Collections.ArrayListSystem.Collections.CollectionBase::get_InnerList( )
IL_000b: callvirt instance int32
System.Collections.ArrayList::get_Count()
IL_0010: blt.s IL_0022
IL_0012: ldstr "ArgumentOutOfRange_Index"
IL_0017: call string System.Environment::GetResourceString(string) IL_001c: newobj instance void
System.ArgumentOutOfRangeException::.ctor(strin g)
IL_0021: throw
IL_0022: ldarg.0
IL_0023: call instance class System.Collections.ArrayListSystem.Collections.CollectionBase::get_InnerList( )
IL_0028: ldarg.1
IL_0029: callvirt instance object
System.Collections.ArrayList::get_Item(int32)
IL_002e: stloc.0
IL_002f: ldarg.0
IL_0030: ldloc.0
IL_0031: callvirt instance void
System.Collections.CollectionBase::OnValidate(obj ect)
IL_0036: ldarg.0
IL_0037: ldarg.1
IL_0038: ldloc.0
IL_0039: callvirt instance void
System.Collections.CollectionBase::OnRemove(int32 ,

object)
IL_003e: ldarg.0
IL_003f: call instance class System.Collections.ArrayListSystem.Collections.CollectionBase::get_InnerList( )
IL_0044: ldarg.1
IL_0045: callvirt instance void
System.Collections.ArrayList::RemoveAt(int32)
IL_004a: ldarg.0
IL_004b: ldarg.1
IL_004c: ldloc.0
IL_004d: callvirt instance void
System.Collections.CollectionBase::OnRemoveComple te(int32,

object)
IL_0052: ret
} // end of method CollectionBase::RemoveAt
"m. pollack" <an*******@discussions.microsoft.com> wrote in messagenews:04****************************@phx.gbl...
Hi all,

I've been using the CollectionBase class to implement a
strongly-typed collection, but I have noticed that the
RemoveAt method does not seem to call the "On" hook
methods (OnRemove, OnRemoveComplete). The Add method works fine, though! I need these to work -- I am exposing the
collection to the user through a PropertyGrid control, and the user can add/remove collection elements with the
(apparently undocumented) Object Collection Editor that
the PropertyGrid invokes, and I need to do some work when that happens...

Is this a bug? I saw a reference to the problem here:

http://lists.ximian.com/archives/public/mono-list/2001-
November/001978.html

Any thoughts?

Thanks, MP

.

Jul 21 '05 #7
See my answer in other thread.
news:%2****************@tk2msftngp13.phx.gbl
"m. pollack" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
Thanks, Mick - I'd be very interested to know what you
come up with... M

-----Original Message-----
The link you gave showed a problem where the On* methods

were not called
when referencing the InnerList.

From the MSDN documention:
\\\
The On* methods are invoked only on the instance returned

by the List
property, but not on the instance returned by the

InnerList property.
///

OnRemove and OnRemoveComplete do work at Runtime, but do

not appear to work
at DesignTime.
What does appear to happen though, is the Collection

Editor clears and
creates a new List whenever you add or remove items from

the List. I've not
got an answer as yet, but I'll also need it shortly.

"m. pollack" <an*******@discussions.microsoft.com> wrote

in message
news:04****************************@phx.gbl...
Hi all,

I've been using the CollectionBase class to implement a
strongly-typed collection, but I have noticed that the
RemoveAt method does not seem to call the "On" hook
methods (OnRemove, OnRemoveComplete). The Add method works fine, though! I need these to work -- I am exposing the
collection to the user through a PropertyGrid control, and the user can add/remove collection elements with the
(apparently undocumented) Object Collection Editor that
the PropertyGrid invokes, and I need to do some work when that happens...

Is this a bug? I saw a reference to the problem here:

http://lists.ximian.com/archives/public/mono-list/2001-
November/001978.html

Any thoughts?

Thanks, MP

.

Jul 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steve M | last post by:
I have subclassed CollectionBase. I have also implemented GetEnumerator(). I have tried to set the DataSource of a DataGrid to an instance of my subclass. However, the items in the grid are not...
2
by: m.pollack | last post by:
Hi all, I have an application which uses a class object that contains a collection. In order to use the PropertyGrid control to expose properties to the user at runtime, I created a...
1
by: alanrn | last post by:
I've implemented a number of strongly-typed collections that inherit from CollectionBase and recently noticed something that I don't fully understand. CollectionBase defines method RemoveAt(). ...
0
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
2
by: Samuel R. Neff | last post by:
What's the advantage of inheriting from CollectionBase as opposed to just implementing IList? It seems that it saves you from having to implement a few properties (Clear, CopyTo, Count,...
7
by: m. pollack | last post by:
Hi all, I've been using the CollectionBase class to implement a strongly-typed collection, but I have noticed that the RemoveAt method does not seem to call the "On" hook methods (OnRemove,...
0
by: LIJO CHEERAN | last post by:
Hello friends I am trying to study about CollectionBase. I have inherited CollectionBase in the class TheCollection.cs. I am using the “TheCollection. in an aspx page to store objects...
3
by: Tony Johansson | last post by:
Hello! Sorry for opening up this task again. I want to fully understand this List that is return from CollectionBase. According to you is List in CollectionBase implemented something like...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.