A am trying to create a series of wrapper classes to encapsulate some classes derived directly from the database.
I want to simply hand in an instance of the database object into the constructor of the wrapper class and not have to manually set each property.
I cannot change the db class B, its not my code or department and Id have to go up 2 levels of management just to talk to someone who could consider changing it.
I know it is possible to simply brute force the solution. by taking an instance of the base class in the constructor and setting each property of the true base class with that instance. like so:
class A :B{
public A(B instance){
this.Prop1 = B.Prop1
//...
this.Prop87 = B.Prop87
}
public string doRandomWrapperFunction(){
return Prop36 + Prop49 + DateTime.Now();
}
}
But some of these objects have over 100 props, and I have about 100 objects I would like to create a wrapper for. So that means I need to write over 1000 lines of just this.Prop59 = B.Prop59. AND they might change in the future.
what I want to have is something like:
class A : B{
public A(B instance){
base = B;//This is the line that I want to compile but can't
}
public string doRandomWrapperFunction(){
return Prop36 + Prop49 + DateTime.Now();
}
}
I really don't want to have to do something like
class A{
public B BaseInstance;
public A(B instance){
this.baseInstance = B;
}
public string doRandomWrapperFunction(){
return BaseInstance.Prop36 + BaseInstance.Prop49 + DateTime.Now();
}
}
because I use class B everywhere
string id = "1234"
B dbObject = getBFromDatabase(id); //I cant change this method.
existingCodeFunctionCall(dbObject.Prop1) //<==this times 1000
and I would have to change all of them to:
A dbObject = new A(getBFromDatabase(id));
existingCodeFunctionCall(dbObject.BaseInstance.Prop1) //<==this times 1000
I simply want to change its declaration from B to A like this:
A dbObject = new A(getBFromDatabase(id));
existingCodeFunctionCall(dbObject.Prop1)//<== this doesnt need to change
//because it automatically has all the properties of the base class.
I understand that I might be way off, and that the solution might have nothing to do with inheritance or the base class, this is just where I am stuck.
Thanks for any help.