How to deal with a sealed class when I wanted to inherit and add properties

You could add an implicit operator to your class.

Eg:

class BackupFileInfo .... {
  /* your exiting code */

  public static implicit operator FileInfo( BackupFileInfo self ){
     return self.FileInfo;
  }
}

You could then treat your BackupFileInfo object like a FileInfo object like so

BackupFileInfo bf = new BackupFileInfo();
...
int mylen = ((FileInfo)bf).Length;

This is one of the classic composition instead of inheritance examples and you went in the right direction.

To solve your property problem just create a property called Length that delegates to the encapsulated FileInfo object.

Tags:

C#

.Net