inheritance

C#: What are virtual events and how can they be used?

How does a virtual event work? How would you override it? How would that work? And in what cases would you do that? Would it for example be an ok replacement for protected OnEvent methods? So that inheriting classes could just override the event and raise it directly? Or would that be wrong or just not work? The MSDN says this about it...

C# - How to reflect the generic parameter that was used for inheritance

Let's say I have the following class hierarchy: TaskViewer inherits from ListViewer<Task> which in turn inherits from ViewerBase. If I debug into a method that is declared in ViewerBase and look at this.GetType(), it correctly returns TaskViewer. However, I cannot find a property or method which will return me the generic parameter tha...

c#: Inherited/interface static member?

Is there a way to require that a class have a particular abstract member? Something like this: public interface IMaxLength { public static uint MaxLength { get; } } Or perhaps this: public abstract class ComplexString { public abstract static uint MaxLength { get; } } I'd like a way enforce that a type (either through inher...

C# reflection and inheritance of static members

Let's say we have these two classes: public class Base { public static int GetInt() { return 1; } } public class Derived : Base { } Let's also say that a piece of code calls Derived.GetInt(). How can I tell from within GetInt() that it was Derived.GetInt() and not Base.GetInt() that was called? What reflection technique do I use...

Creating a decorator in a class with access to the (current) class itself

Currently, I'm doing it in this fashion: class Spam(object): decorated = None @classmethod def decorate(cls, funct): if cls.decorated is None: cls.decorated = [] cls.decorated.append(funct) return funct class Eggs(Spam): pass @Eggs.decorate def foo(): print "spam and eggs" ...

C#: Any reasons why you should not declare an event backing field protected?

Are there any reason why you should not declare an event backing field protected? For example to prevent having to create OnSomeEvent methods for all your events. For example like this: protected SomeEventHandler someEvent; readonly object someEventLock = new object(); public event SomeEventHandler SomeEvent { ...

value of this in the prototype inheritance

If I have: var Shape = function() { this.toString_ = function() { alert(this.UL)} } Shape.prototype.UL = "<UL></UL>" var _2D = function() { this.name = "_2D"} _2D.prototype = new Shape() var i = new _2D() i.toString_() when I call i.toString_() the JS engine try to find if i has toString_ function and not finding it goes int...

How to add event handler to an inherited winform control?

I need to add an event handler to an inherited control like a datagridview but Visual Studio doesn't allow me. Isn't there a way for an inherited control to fire a base event handler AND the inherited one? in a sequence I specify? ...

Are there any scenarios in which multiple inheritence is necessary?

Are there any scenarios in which multiple inheritence is necessary? Please provide examples. ...

Downcasting in C#

I'm facing a problem that I don't know how to solve and am hoping the community can help. I'm writing an app that manages "Lead" objects. (These are sales leads.) One part of my program will import leads from a text file. Now, the text file contains lots of potential leads, some of which I will want to import and some of which I won't. ...

Is there a way of finding what .NET classes implements a certain interface?

For example if I wanted to see what my .NET options were for something implementing IList or IDictionary. Is there a way to find that for example in the MSDN documentation? ...

Accessing Parent Namespace in C++

Hello, all :) I've got a scenario like the following: class criterion { // stuff about criteria... }; namespace hex { class criterion : public criterion //does not compile { //This should inherit from the //A hex specific criterion //criterion class in the global namespace ...

How to enforce a method call (in the base class) when overriding method is invoked?

I have this situation that when AbstractMethod method is invoked from ImplementClass I want to enforce that MustBeCalled method in the AbstractClass is invoked. I’ve never come across this situation before. Thank you! public abstract class AbstractClass { public abstract void AbstractMethod(); public void MustBeCalled() { ...

Inheritting from ListViewItemCollection

I'm trying to create a class that inherits from ListViewItemCollection, and I got this error: "No overload for method 'ListViewItemCollection' takes '0' arguments". Any idea how to fix it or how I can inherit from this class. All suggestions are welcome. Greetings! ...

Why shouldn't you extend JFrame and other components?

I've seen this come up here a few times, but in the postings I've seen, no one explained it. Why shouldn't I extend JFrame (or any component)? Are there conditions where I should extend a component, or is this a firm rule that you don't? ...

when will "a" tag not inherit color attribute of parent tag?

Here is my code: css part .blue { color:#6E99E1; font-size:9px; } markup part <span class="blue">::<a href="/equipment_new.php">CLICK HERE</a>:: to view our New Equipment inventory. <br /><br /></span> I've somehow triggered something that prevented "a" tag from inheriting color of parent tag(here "span") now. ...

does Inheritance really hide methods?

I am getting the following Compiler Warning: 'Resources.Foo.GetType()' hides inherited member 'object.GetType()'. Use the new keyword if hiding was intended. Resources.NET\Resources\Class1.cs 123 20 Resources for this (very simplified) code: public interface IFoo { int GetType(); string GetDisplayName(); } public class ...

Override an overridden method (C#)

Hi, I'm trying to override an overridden method (if that makes sense!) in C#. I have a scenario similar to the below, but when I have a breakpoint in the SampleMethod() in the "C" class it's not being hit, whilst the same breakpoint in the "B" method is being hit. public class A { protected virtual void SampleMethod() {} } p...

How to access functions in child classes?

A child class can access protected functions in parent class,but the parent class can't access protected functions in child class. I'd like to keep both classes as private as possible.The parent class is a form and only once instance is used.All functions in the child class are static,it inherits from the parent class. How is it possib...

How to Avoid Calling Viritual Methods from a Base Constructor

I have an abstract class in a library. I'm trying to make it as easy as possible to properly implement a derivation of this class. The trouble is that I need to initialize the object in a three-step process: grab a file, do a few intermediate steps, and then work with the file. The first and last step are particular to the derived class....