Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 690
  • Last Modified:

Extending FileInfo

I'd like to add a Member to the FileInfo class, but FileInfo is sealed. I really don't know enough to write my own FileInfo-like class, what can I do?
1 Solution
it might be a pain, but make a class with a private instance of a FileInfo object.  Then you can add your methods, and just direct the fileinfo methods to the private instance.

well... here is the FileInfo Class signature:

But I think your best bet is to follow NTAC's advice.

// from module 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll'
public sealed class System.IO.FileInfo :

    // Fields

    // Constructors
    public FileInfo(string fileName);

    // Properties
    public FileAttributes Attributes { get; set; }
    public DateTime CreationTime { get; set; }
    public DateTime CreationTimeUtc { get; set; }
    public DirectoryInfo Directory { get; }
    public string DirectoryName { get; }
    public bool Exists { virtual get; }
    public string Extension { get; }
    public string FullName { virtual get; }
    public DateTime LastAccessTime { get; set; }
    public DateTime LastAccessTimeUtc { get; set; }
    public DateTime LastWriteTime { get; set; }
    public DateTime LastWriteTimeUtc { get; set; }
    public long Length { get; }
    public string Name { virtual get; }

    // Methods
    public System.IO.StreamWriter AppendText();
    public System.IO.FileInfo CopyTo(string destFileName);
    public System.IO.FileInfo CopyTo(string destFileName, bool overwrite);
    public System.IO.FileStream Create();
    public virtual System.Runtime.Remoting.ObjRef CreateObjRef(Type requestedType);
    public System.IO.StreamWriter CreateText();
    public virtual void Delete();
    public virtual bool Equals(object obj);
    public virtual int GetHashCode();
    public virtual object GetLifetimeService();
    public virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
    public Type GetType();
    public virtual object InitializeLifetimeService();
    public void MoveTo(string destFileName);
    public System.IO.FileStream Open(System.IO.FileMode mode);
    public System.IO.FileStream Open(System.IO.FileMode mode, System.IO.FileAccess access);
    public System.IO.FileStream Open(System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share);
    public System.IO.FileStream OpenRead();
    public System.IO.StreamReader OpenText();
    public System.IO.FileStream OpenWrite();
    public void Refresh();
    public virtual string ToString();
} // end of System.IO.FileInfo
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

derekthorntonAuthor Commented:
Sorry I took so long to get back to you!
derekthorntonAuthor Commented:
What did he post?  All he posted was a link to docuemtation that comes with .net...
derekthorntonAuthor Commented:
.... That was the entire FileInfo Source Code.
derekthorntonAuthor Commented:
.... That was the entire FileInfo Source Code.

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now