How to remove a method from CollectionBase
-
How can I remove a method from System.Collections.CollectionBase? Say, I have a class: public class MyList : System.Collections.CollectionBase{} I have all the members of the collection base such as Add(object), Remove(object), RemoveAt(index), etc... I want to get rid of RemoveAt() and Insert() methods.. Do you have a solution? Thanks in advance..
Radgar
-
How can I remove a method from System.Collections.CollectionBase? Say, I have a class: public class MyList : System.Collections.CollectionBase{} I have all the members of the collection base such as Add(object), Remove(object), RemoveAt(index), etc... I want to get rid of RemoveAt() and Insert() methods.. Do you have a solution? Thanks in advance..
Radgar
-
How can I remove a method from System.Collections.CollectionBase? Say, I have a class: public class MyList : System.Collections.CollectionBase{} I have all the members of the collection base such as Add(object), Remove(object), RemoveAt(index), etc... I want to get rid of RemoveAt() and Insert() methods.. Do you have a solution? Thanks in advance..
Radgar
You have a couple of options: 1. Do not derive from CollectionBase and instead implement ICollection and/or IList directly. This will allow you to either not include undesirable insertion/removal methods or, where those methods are required by the collection interfaces, to throw a NotImplementedException. 2. Derive from CollectionBase but override the protected OnInsert() and OnRemove() methods and throw a NotImplementedException. (You have to be careful with OnInsert(), though, as that will also get called for Add(), which you *do* want to allow.) -Phil
-
You have a couple of options: 1. Do not derive from CollectionBase and instead implement ICollection and/or IList directly. This will allow you to either not include undesirable insertion/removal methods or, where those methods are required by the collection interfaces, to throw a NotImplementedException. 2. Derive from CollectionBase but override the protected OnInsert() and OnRemove() methods and throw a NotImplementedException. (You have to be careful with OnInsert(), though, as that will also get called for Add(), which you *do* want to allow.) -Phil