Skip to content

Stream related constants for default constructor parameters should be public #29096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scottdorman opened this issue Mar 27, 2019 · 7 comments
Closed
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.IO

Comments

@scottdorman
Copy link

The Stream classes have various constants that define default values (for things like the default buffer size) which are either internal or private. These should become public so they can be referenced by calling code (to provide the proper defaults when having to use some of the various constructor overloads).

In addition, there are a few defaults used (for example, the default encoding for StreamReader) which are not defined by a constant but instead repeated in the various constructor overloads as a direct parameter. These should be pulled out as new public constants as well.

Originally posted by @JeremyKuhne in https://github.com/dotnet/corefx/issues/8173#issuecomment-477301802

@svick
Copy link
Contributor

svick commented Mar 28, 2019

to provide the proper defaults

.Net already has a way to do this: optional parameters with defaults. Is providing these values as their own members really better than optional parameters?

@JeremyKuhne
Copy link
Member

.Net already has a way to do this: optional parameters with defaults. Is providing these values as their own members really better than optional parameters?

Normally no. In this case, however, we've got existing constructors that make adding default parameters untenable.

@scottdorman
Copy link
Author

Optional parameters with defaults won't work in this case, as @JeremyKuhne mentioned. Unless the decision from (https://github.com/dotnet/corefx/issues/470#issuecomment-147809240) is going to be reversed (or ignored), optional parameters aren't recommended on public API surfaces. Also, @svick, this is the same issue you referenced in #17157:

Assuming optional arguments are okay (they probably aren't, see #13995),

@GSPP
Copy link

GSPP commented Mar 29, 2019

If these values are made public it should be a static property. const is burned into calling binaries at compile time and it also precludes any ability to chose a dynamic value at runtime.

I personally think this should not be public and any issues with constructor overloads should be dealt with in a different way. Various ideas for that have been proposed. A solution such as new FileStream(..., FileStream.DefaultBufferSize, ...) seems unappealing to me.

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 5.0 milestone Feb 1, 2020
@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 23, 2020
@carlossanlop carlossanlop removed the untriaged New issue has not been triaged by the area owner label Feb 24, 2020
@carlossanlop carlossanlop modified the milestones: 5.0, Future Feb 24, 2020
@carlossanlop
Copy link
Contributor

@GSPP if we add it as a a static property to the Stream base class, we would not be able to make it virtual because it's static.

I mention this because many of our own stream-derived types define their own internal or private defaultBufferSize fields, with different values, so they would need to be able to override it. Here's a query with all the places where we already define a DefaultBufferSize. Notice they are internal or private, and a lot of the results belong to stream-derived classes: https://source.dot.net/#q=defaultbuffersize

Copy link
Contributor

Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

This process is part of our issue cleanup automation.

@dotnet-policy-service dotnet-policy-service bot added backlog-cleanup-candidate An inactive issue that has been marked for automated closure. no-recent-activity labels Apr 11, 2025
Copy link
Contributor

This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

@dotnet-policy-service dotnet-policy-service bot removed this from the Future milestone Apr 25, 2025
@github-actions github-actions bot locked and limited conversation to collaborators May 25, 2025
@dotnet-policy-service dotnet-policy-service bot removed no-recent-activity backlog-cleanup-candidate An inactive issue that has been marked for automated closure. labels May 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.IO
Projects
None yet
Development

No branches or pull requests

7 participants