Description
Problem
The FileStream
class has a variety of constructor overloads which allow for configuring different attributes. In general, you can choose a constructor depending on which attributes of the stream you care to specify.
The problem, as I see it, is that if you want to specify a value for useAsync
(FileStream
), you always have to also specify a value for bufferSize
.
This is frustrating because as a caller it's fairly obvious when I want useAsync
; in contrast, it seems rare that you'd know what value would be appropriate for bufferSize
. In most cases the default would be preferable.
However, the constructors today force you to specify some buffer size. As a result, devs are either looking up the actual default in ref source and writing it in (which has the drawback that if the default changed the code would not reflect it) or worse are just picking something arbitrary which very well might hurt their app's performance.
Proposal
Introduce constructor for FileStream
where many "advanced" options are defaulted, much like we now have for StreamReader
/StreamWriter
. For example:
public FileStream (string path, FileMode mode, FileAccess access, FileShare share = FileShare.None, int bufferSize = -1, bool useAsync = false);