Skip to content
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

API Proposal: add ReadLines to TextReader #48255

Open
NetMage opened this issue Feb 12, 2021 · 2 comments
Open

API Proposal: add ReadLines to TextReader #48255

NetMage opened this issue Feb 12, 2021 · 2 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.IO needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Milestone

Comments

@NetMage
Copy link

NetMage commented Feb 12, 2021

Background and Motivation

We have File.ReadLines but not TextReader.ReadLines, which would work with StringReader and StreamReader and make using LINQ with lines easier and standardized.

Proposed API

namespace System.IO
{
    public abstract partial class TextReader : MarshalByRefObject, IDisposable
    {
        public virtual IEnumerable<string> ReadLines()
        {
            string line;
            while ((line = sr.ReadLine()) != null)
                yield return line;
        }
    }
}

Usage Examples

Example using ReadLines with LINQ to process a CSV from a StringReader:

    var ans = String.Join("\n",
                          sr.ReadLines()
                            .Select(line => line.Split(';'))
                            .Select(columns => String.Join(";", map.Select(pos => columns[pos]))));
@NetMage NetMage added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Feb 12, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Linq untriaged New issue has not been triaged by the area owner labels Feb 12, 2021
@ghost
Copy link

ghost commented Feb 12, 2021

Tagging subscribers to this area: @eiriktsarpalis
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and Motivation

We have File.ReadLines but not TextReader.ReadLines, which would work with StringReader and StreamReader and make using LINQ with lines easier and standardized.

Proposed API

namespace System.IO
{
    public abstract partial class TextReader : MarshalByRefObject, IDisposable
    {
        public virtual IEnumerable<string> ReadLines()
        {
            string line;
            while ((line = sr.ReadLine()) != null)
                yield return line;
        }
    }
}

-->

Usage Examples

Example using ReadLines with LINQ to process a CSV from a StringReader:

    var ans = String.Join("\n",
                          sr.ReadLines()
                            .Select(line => line.Split(';'))
                            .Select(columns => String.Join(";", map.Select(pos => columns[pos]))));

-->

Author: NetMage
Assignees: -
Labels:

api-suggestion, area-System.Linq, untriaged

Milestone: -

@adamsitnik
Copy link
Member

@bartonjs We (@carlossanlop and @Jozkee) are surprised that this has not been proposed before and wonder whether there is a good reason for that. We have introduced similar File-specific APIs in the past (#18344). Do you believe that it's worth presenting it in the API Review meeting?

@adamsitnik adamsitnik added needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed untriaged New issue has not been triaged by the area owner labels Feb 18, 2021
@adamsitnik adamsitnik added this to the Future milestone Feb 18, 2021
@adamsitnik adamsitnik added this to To do in System.IO - File system via automation Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.IO needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Projects
Development

No branches or pull requests

3 participants