Why can't you get it done through a public auto property like below. BTW, what you are trying to have is Composition
wherein bar
object is composed of foo
object. Not sure why you are still inheriting from foo
then?
public class bar : Foo
{
public int ID { get; set; }
public Foo baseinstance { get; set;}
public bar(Foo instance)
{
baseinstance = instance;
}
}
I am not absolutely sure but from your posted code (specifically the below part) it feels like you are trying to call the base class constructor or constructor initializer
since you said
I am looking to get a child class instantiated using a parent instance
to set all of the inherited variables.
public bar(Foo instance)
{
base = instance;
}
Which should actually be
public bar(Foo instance) : base()
{
//child instance initialization
}
But that's not needed for a parameterless constructor cause when you instantiate child object constructor initializer will get invoked and base class will gets initialize first in-order to have the base member initialized before child initialization.
If you have parameterized constructor in base and in child then you can explicitly call base constructor