Skip to main content
example code is pointless
Source Link
dfhwze
  • 13.9k
  • 3
  • 38
  • 101

Single Responsibility

Your method does 2 things: (1) parse entities from CSV and (2) post entities over a web service. You should create a dedicated method to do the parsing. This improves (re-)usability and testability of your code.

public IEnumerable<MassUploadUser> ParseUsersFromCsv(TextFieldParser parser)
{
    // .. CR: code left out for brevity
}

public void UploadUsers(IEnumerable<MassUploadUser> users)
{
    foreach (var user in users)
    {
        // After the for loop, I have some additional logic
        // to serialize the newly-created object to JSON
        // and then POST it to a RESTful API
        DoPostToWebService(user, password);
    }
}

Single Responsibility

Your method does 2 things: (1) parse entities from CSV and (2) post entities over a web service. You should create a dedicated method to do the parsing. This improves (re-)usability and testability of your code.

public IEnumerable<MassUploadUser> ParseUsersFromCsv(TextFieldParser parser)
{
    // .. CR: code left out for brevity
}

public void UploadUsers(IEnumerable<MassUploadUser> users)
{
    foreach (var user in users)
    {
        // After the for loop, I have some additional logic
        // to serialize the newly-created object to JSON
        // and then POST it to a RESTful API
        DoPostToWebService(user, password);
    }
}

Single Responsibility

Your method does 2 things: (1) parse entities from CSV and (2) post entities over a web service. You should create a dedicated method to do the parsing. This improves (re-)usability and testability of your code.

Source Link
dfhwze
  • 13.9k
  • 3
  • 38
  • 101

Single Responsibility

Your method does 2 things: (1) parse entities from CSV and (2) post entities over a web service. You should create a dedicated method to do the parsing. This improves (re-)usability and testability of your code.

public IEnumerable<MassUploadUser> ParseUsersFromCsv(TextFieldParser parser)
{
    // .. CR: code left out for brevity
}

public void UploadUsers(IEnumerable<MassUploadUser> users)
{
    foreach (var user in users)
    {
        // After the for loop, I have some additional logic
        // to serialize the newly-created object to JSON
        // and then POST it to a RESTful API
        DoPostToWebService(user, password);
    }
}