Solved

Extending FileInfo

Posted on 2004-04-23
9
624 Views
Last Modified: 2012-08-13
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?
0
Comment
Question by:derekthornton
9 Comments
 
LVL 4

Expert Comment

by:NTAC
ID: 10902775
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.
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 10902961




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 :
    System.IO.FileSystemInfo,
    System.Runtime.Serialization.ISerializable
{

    // 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
0
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 500 total points
ID: 10905679
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 2

Author Comment

by:derekthornton
ID: 10986799
Sorry I took so long to get back to you!
0
 
LVL 4

Expert Comment

by:NTAC
ID: 11009287
????
0
 
LVL 2

Author Comment

by:derekthornton
ID: 11009347
What?
0
 
LVL 4

Expert Comment

by:NTAC
ID: 11009430
What did he post?  All he posted was a link to docuemtation that comes with .net...
0
 
LVL 2

Author Comment

by:derekthornton
ID: 11009450
.... That was the entire FileInfo Source Code.
0
 
LVL 2

Author Comment

by:derekthornton
ID: 11009456
.... That was the entire FileInfo Source Code.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question