jshepler

jshepler

  • NA
  • 63
  • 0

Getting derived object from the base object

Oct 5 2004 11:09 AM
I extended the System.Net.Sockets.TcpClient class and I cannot figure out how to get an instance of my derived class when given an instance of the base TcpClient class. For example, the TcpListner.AcceptTcpClient() method returns a TcpClient object. I would like to take that and get an instance of my derived class. I tried to just cast it, but I get an invalid cast error - which I expected since the base object wasn't boxed from the derived object. I tried to just assign the base object in the constructor of the derived class: new MyTcpClient(TcpClient client) { base = client; } but it wouldn't compile - "Use of keyword base is not valid in this context". Can something like this even be done?

Answers (7)