Re: Add custom method to File Class
- From: joecool1969@xxxxxxxx
- Date: Fri, 17 Apr 2009 08:50:58 -0700 (PDT)
On Apr 17, 11:16 am, "Alberto Poblacion" <earthling-
quitaestoparacontes...@xxxxxxxxxxxxx> wrote:
<joecool1...@xxxxxxxx> wrote in message
news:991a5a9a-9a69-4fc3-a142-583052de0961@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I would like to create a class that inherits the File Class so I can
add a method to it. Then my class will have all of the functionality
of the original File class with the addition of my custom method.
But it appears that the File Class is a static class and you cannot
inherit from a static class.
Is there some way this can be done?
Instead of inheriting, you could encapsulate the class inside your own.
In other words, write your own class, declare a File inside your class, and
add your method inside your class. You can either expose the File itself
through a public property of your class, or add methods in your class to
call the methods in the encapsulated File.
Alternatively, you could use the FileInfo class instead of the File
class. FileInfo provides just about the same functionality but uses instance
methods instead of static methods. You can still not inherit from it because
it is a sealed class, but you can add an Extension method (if you are using
C# 3.0), which may be adequate for your needs.
Thanks for the replies.
Specifically I woud like a method that takes two parameters, paths to
two files, and returns true if the files are identical or false if
there are any differences. Like File.Compare(path1, path2).
.
- References:
- Add custom method to File Class
- From: joecool1969
- Re: Add custom method to File Class
- From: Alberto Poblacion
- Add custom method to File Class
- Prev by Date: Re: Error handling in Windows Service
- Next by Date: Re: Add custom method to File Class
- Previous by thread: Re: Add custom method to File Class
- Next by thread: Re: Add custom method to File Class
- Index(es):
Relevant Pages
|