Again disclaimer disclaimer still learning C# and OOP generally so I hope you'll be patient with me :)
I am currently working with a CMS that has a class called FileVersion
which basically contains a list of properties pertaining to a file such as filename, filetype, size in bytes, id, date uploaded, is-latest-version, etc.
A list of FileVersion
s is contained within a File
which has it's own unique ID. When you want to download a particular file from the CMS, the URL is built using something like the following:
string URL = "/files/"+file.id.toString()+"/"+file.fileVersion.Last().filename;
Now for a particular control I'm working on (dealing specifically with files that are documents), it makes sense to be able to store the URL along with all the other FileVersion
information for later use. So what I've decided to do is create my own class called DocumentVersion
which extends FileVersion
. This is what it looks like:
public partial class DocumentVersion : FileVersion
{
public DocumentVersion() : base() { }
public string link;
}
Now I should note, that it appears that I don't need to implement an interface here - but don't take that as gospel, that's why I'm here.
However when I try to cast my FileVersion
as a DocumentVersion
like so:
DocumentVersion dv = ((DocumentVersion)fileversion);
I get the following exception:
Unable to cast object of type 'Foo.CMS.FileVersion' to type 'CoA.DocumentVersion'.
My inkling is that it's because I'm trying to extend a class in a different namespace from where the original resides, but like I said, OOP is relatively new to me so I could be wrong.
Thanks in advance for your help. This community has been so valuable! I just hope once I'm more skilled up I can give some back :).