Inherit values from a base class parameter in a constructor?

  • Thread starter Thread starter Bjørn Brox
  • Start date Start date
B

Bjørn Brox

Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit


Hi!

Using .Net CF3.

I am receiving some class objects from a web service, and would like to
store this in my own class object with some additional values where the
base values is received as a parameter in the constructor.

My idea is something like the code example below, which gives the error
"Use of keyword 'base' is not valid in this context".

Any idea on how to solve this without having to copy each element or by
having my own "base" variable?

public class MyPassengerRC : PassengerRC
{
public bool is_arrived;

public MyPassengerRC(PassengerRC p)
{
base = p;
}
}
 
Bjørn,

You can't do this. Basically, you will have to assign each member of
the base class to the corresponding member of the class you are trying to
copy the contents to.
 
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Hi!

Using .Net CF3.

I am receiving some class objects from a web service, and would like to
store this in my own class object with some additional values where the
base values is received as a parameter in the constructor.

My idea is something like the code example below, which gives the error
"Use of keyword 'base' is not valid in this context".

Any idea on how to solve this without having to copy each element or by
having my own "base" variable?

public class MyPassengerRC : PassengerRC
{
public bool is_arrived;

public MyPassengerRC(PassengerRC p)
{
base = p;
}
}

you could create a constructor in your base class
PassengerRC(PassengerRC passengerRC)
{
//you will have to assign it here..
}


public class MyPassengerRC : PassengerRC
{
public bool is_arrived;

public MyPassengerRC(PassengerRC p)
: base(p)
{

}
}
 
parez skrev:
you could create a constructor in your base class
PassengerRC(PassengerRC passengerRC)
{
//you will have to assign it here..
}

As I said: The base class PassengerRC comes from a webservice, not
locally declared and maintained.

Adding something to this class is not possible (If I could I would put
my own variables there).
 
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Hi!

Using .Net CF3.

I am receiving some class objects from a web service, and would like to
store this in my own class object with some additional values where the
base values is received as a parameter in the constructor.

My idea is something like the code example below, which gives the error
"Use of keyword 'base' is not valid in this context".

Any idea on how to solve this without having to copy each element or by
having my own "base" variable?

     public class MyPassengerRC : PassengerRC
     {
         public bool is_arrived;

         public MyPassengerRC(PassengerRC p)
         {
            base = p;
         }
     }

Hi,

that is not possible at all.


You have two options:
- If your class inherit from the received (do this only if they share
some features) you can manually assign the base properties,
- If you do not have to inherit your class can hold a refeence to the
received class as a member variable and you simply expose the
properties you need:

public class MyPassengerRC :
{
PassengerRC p;
public string Name{ get{ p.Name;} }
 
Back
Top