|
In point of fact, more often than not interfaces simply aren't appropriate.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I'm glad I'm not the only one that thought that was a WTF thing to do in C#.
Jeremy Falcon
|
|
|
|
|
This wouldn't do?
class EventCollection<T> : List<T>
{
}
class MyCollection : EventCollection<MyClass>
{
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Oops, it took me too long to write my reply (see below)
|
|
|
|
|
Why yes, that would work. But I still want multiple inheritance.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I'm probably misinterpreting what it is that you want to do, but wouldn't something like this help?
public abstract class AbstractCollection<T> : List<T>
{
public delegate void OnItemAddedEventHandler(T item);
public event OnItemAddedEventHandler OnItemAdded;
public new void Add(T item)
{
if (OnItemAdded != null)
{
OnItemAdded(item);
}
base.Add(item);
}
public new void Remove(T item)
{
base.Remove(item);
}
public new void RemoveAt(int index)
{
base.RemoveAt(index);
}
}
The whole thing's rigged to blow, touch those tanks and "boooom"!
modified 31-Aug-21 21:01pm.
|
|
|
|
|
Why not write a class with your custom event code which inherits the List object, and then inherit this class in MyCollection/whatever?
At least then you wouldn't have to duplicate the event code...
...or use the custom event code class as a Property in MyCollection?
(just some thoughts, of course it may not work this way for your purposes...)
|
|
|
|
|
List<T> probably isn't the class you want to inherit anyway.
Try Collection<T>[^] instead
|
|
|
|
|
|
No, I really do want List<t>.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
1) You can use extension methods.
2) For future maintenance purpose, almost always a better idea to use composition instead of multiple inheritance.
3) If the list is a private member of a class, then the custom method could be added to that class instead.
4) You can also use composition and have a property that returns the list if for example, your class purpose is to build a list.
In practice, you might loose a few minutes now but the application will usually be more maintainable if every class follow the SOLID principle.
When refactoring code, complex hierarchy are much harder to work with...
Philippe Mori
|
|
|
|
|
|
|
My previous team got around this by implementing 15 layers of bullshit inheritance. What? Not good enough?
|
|
|
|
|
|
Seen it before (and cheaper), but cool none the less
|
|
|
|
|
|
I and a colleague actually sat on our desks with case of Becks and sang that song for real. The boss was out, we got told off for not including him when he saw the video of us doing that!
|
|
|
|
|
I don't know where she got it from. I just picked the first link with a picture of the shirt.
The one I have is a little different from what's shown.
|
|
|
|
|
Do Welshman like both male and female sheep, or is it just ewe?
|
|
|
|
|
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
Pompey, now you've done gone hurt his feelings!
How do we preserve the wisdom men will need,
when their violent passions are spent?
- The Lost Horizon
|
|
|
|
|
Nah - it's just every time a post subject names me specifically it's not going to be good news...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I'm curious to know how many cultures have a specific ethnicity which is popularly renowned to consort with sheeps.
In Italy we say that of people from Sardinia, in England it is said of Welsh... does anybody know more of them?
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver
"When you have eliminated the JavaScript, whatever remains must be an empty page." -- Mike Hankey
"just eat it, eat it"."They're out to mold, better eat while you can" -- HobbyProggy
|
|
|
|