There is a lot of duplication of functions in the My.Computer.FileSystem
and System.IO.File
namespaces.
So what exactly is the difference between:
My.Computer.FileSystem.CopyFile(source, dest, True)
and:
System.IO.File.Copy(source, dest, True)
Is there a performance difference? What is everyone's opinion on which which has the edge on read-ability? I personally use the My.Computer
Namespace but that is just habit now.
My.* is simply a set of facade-pattern classes implemented for VB.NET that encompass common System.IO* (and other) operations. There is a very tiny performance hit since you're going through an extra layer of abstraction but you have to decide if it's worth optimizing for that. I would suggest using whichever way makes sense to you and others in your shop.
If you examine the code for My.Computer.FileSystem.CopyFile
with .NET Reflector you will see that the method wraps many System.IO classes such as File and Directory and especially the File class' Copy, Move and Delete methods. Snippet:
'lots of other code snipped out for brevity and to show the use of System.IO classes...
Directory.CreateDirectory(FileSystem.GetParentPath(str))
'snip
If
' snip
Else
File.Delete(str)
File.Move(path, str)
End If
Else
File.Move(path, str)
End If
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With