I have four classes. Request, DerivedRequest, Handler, DerivedHandler. The Handler class has a property with the following declaration:
public abstract Request
In the C# language you are not allowed to change the signature of an inherited method, unless you substitute it with another method with the same name. This technique is referred to as "member hiding" or "shadowing".
If you are using .NET 2.0 or later, you could solve this problem by turning the return type of the Request
property into a generic type parameter of the Handler
class. The DerivedHandler
class would then specify the DerivedRequest
class as argument for that type parameter.
Here's an example:
// Handler.cs
public class Handler where TRequest : Request
{
public TRequest Request { get; set; }
}
// DerivedHandler.cs
public class DerivedHandler : Handler
{
}