c# overriding class questions

M

MattB

Hello I have base class called DocumentManager.cs
I then have another class which inherits from DocumentManager
which is a TestManager.cs

I want to override the base method and want to pass properties
on TestManager into DocumentManager, and then load the TestManager
properties with values from Document manager....

I am really confused all the examples I can find seem like simple
Animal->Dog type instructions. Basically in DocumentManager
I have a constructor....

public DocumentManager(string sqlConnectionString, string
rootFilePath)
{
sqlconn = sqlConnectionString;
rootFilePath = rootFilePath;
}

and some fields and properties, this plus other like
FileIDReference,FileName,FilePath,FullFilePath;

private string rootFilePath;

public virtual string RootFilePath
{
get
{
return rootFilePath;
}
set
{
rootFilePath = value;
}
}

then a method

public virtual int AddDocument(string _filePath)
{
this.FilePath = createDirectory();
this.FileName = Path.GetFileName(_filePath);
DocumentManagerDataAccess dmda = new
DocumentManagerDataAccess(sqlconn, rootFilePath);
this.FileIDReference = dmda.AddDocumentToDMInfo(this.FilePath,
this.FileName);
this.FullFilePath = this._filepath + this.FileIDReference + "."
+this.FileName;
return this.FileIDReference;
}

Then in my TestManager Class I have similar properties and constuctor
but in
my overrided AddDocument method. I am doing....

public override int AddDocument(string _filePath)
{
base.AddDocument(_filePath);
}

but somehow my TestManager constructor

public TestManager(string sqlConnectionString, string rootFilePath)
{
sqlconn = sqlConnectionString;
rootFilePath = rootFilePath;
}

doesn't pass on the sqlconnect string to the overriden class, also I
need to populate the TestManager properties with those of the
DocumentManager....

Besides when I do the above I just get this error....
"Declaration referenced in a method implementation can not be a final
method"

Can anyone suggest how to go about this in a better way for now I am
just doing the obvious.....

public override int AddDocument(string _filePath)
{
DocumentManager dm = new DocumentManager(sqlconn,rootFilePath);
this.FileIDReference = dm.AddDocument(_filePath);
this.FilePath = dm.FilePath;
this.FileName = dm.FileName;
this.FullFilePath = dm.FullFilePath;
set dm = null;
return this.FileIDReference;
}

Thanks,
Mags
 
J

james

add this

public TestManager(string sqlConnectionString, string rootFilePath) : base
(string sqlConnectionString, string rootFilePath)

to your subclass constructor

JIM
 
V

Vijaye Raji

You can make your sqlConn string protected, in the base class. That way,
you can access the member from a derived class but not from outside.

-vJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top