I have a block of code that needs to open and read a lot of small text files from a NAS server using UNC paths. This code is part of a module that was originally written in C++
I don't really have a specific answer to why the .NET implementation is so chatty, but
this behaviour would be due to the implementation of System.IO.FileStream
as all that File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
is doing is passing the parameters to the FileStream constructor.
public static FileStream Open(string path, FileMode mode, FileAccess access, FileShare share)
{
return new FileStream(path, mode, access, share);
}
Changing the behaviour of FileStream would mean that you would basically have to re-implement the FileStream class which will require a lot of effort.
Your other more simpler alternative would be to create a native wrapper that calls the C++ code you gave. Then call the native wrapper from your C# code.