I'm curious whether it is possible to cast from one type to another type that inherits the top level type.
For example (not a great example but hey)
From Openedge.Core.String to Package.libs.CustomString. CustomString would inherit from Openedge.Core.String.
I have tried simply casting however an "Invalid Cast" error is thrown. This is leading me to believe that this isn't the correct approach to this. Could anyone clarify how this should be handled?
I guess I could in theory have CustomString with a constructor that takes an OpenEdge.Core.String and copies over all it's properties but I wouldn't have thought it would require that sort of overhead.
Perhaps string was a poor example. So we are actually looking to take Openedge.Web.WebRequest and extend it a little. We have tried both implementing the same interfaces and inheriting from it but haven't been able to cast to our custom object in either instance.
As I said previous; this could have been the wrong approach. I simply couldn't see a better method that would enable us to extend the WebRequest object. So you're suggesting that the only way to do this is to new up a new instance of the Custom Web Request and pass in what we need?
Why do you need to cast or new anything. Any subclass can be treated as one of its superclasses as long as one confines oneself to the methods and properties of the superclass. E.g., one can have a method in some class which has a parameter defined as the superclass and then call that method passing in any of the subclasses of that superclass. And, as has been hinted, one can define the message in terms of an interface and pass in any object which supports that interface.
Consulting in Model-Based Development, Transformation, and Object-Oriented Best Practice http://www.cintegrity.com
You might have to post some code. I'm not sure why are you not able to use you custom class. Are you by any chance trying to up-cast WebRequest to your custom WebRequest class when the object was NEWed as WebRequest? You will need to NEW it as custom WebRequest and not just plain WebRequest. Like what Thomas stated, you can treat a instance of a subclass as either instance of the subclass and superclass, but you cannot treat an instance of the superclass as an instance of the subclass.
I can appreciate that up-casting my not be possible. However we are given the existing Web Request from a process out of our control and ideally wanted to add a little bit of extra functionality to it.
So an external process is creating an instance of the WebRequest for you and possibly retrieve it using a property? Unless you can specify (or pass) your own instance of WebRequest, I don't think you will be able to use a custom WebRequest.
So I think we have solved the problem. It was within PASOE and we weren't previously aware that you could override the HandleRequest Method in the Web Handler. This seems to have solved the problem and we can now new up the custom web request. Thanks everyone for your input.