views:

44

answers:

2

I have a base clase "AsyncHandlerBase"

 public class CameraAlertsQuery : AsyncHandlerBase

the base class is inherited by multiple pages. is there any way in the base class to execute specific code when a particular class is inheriting it? I would have that particular code executed on the page itself, but it is not possible in this case.

+2  A: 

It is doable but I strongly recommend against it. Building this sort of knowledge in to the base class makes it difficult to maintain.

What you can do instead is create an abstract (or empty virtual) method in the base class, overridden in the child

mfeingold
A: 

I hestitate to write this, because this is definately going to introduce a "code smell" that is going to plague you down the road sometime. But, if you really must, you can check the type of the calling object from within your base class method:

if (this.GetType().Equals(typeof(DerivedClass)))
{
   ....
}
Dave
Thanks Dave, this worked the way I needed it to.
Ben