I have a class that expects an IWorkspace
to be created:
public class MyClass {
protected IWorkspace workspace;
public MyClass(IWorkspace w) {
this.workspace = w;
}
}
and a derived class Derived
. In this derived class I have a copy-constrcutor that should create an instance of Derived
based on an instance of MyClass
.
public class Derived : MyClass{
public Derived(MyClass m) : base(m.workspace) { }
}
The above won´t compile with following error:
Cannot access protected member MyClass.workspace' via a qualifier of type 'MyClass'; the qualifier must be of type 'Derived' (or derived from it)
So what I´m trying to achieve is copying the base-class´ members to the derived one and create into a new instance of the latter. The reason why I do not use a constructor for IWorkspace
within my derived class is that I do not have any access to such a workspace within the client-code, only to the instance of MyClass
to be copied.