-
-
Save CopperStarSystems/95883982871c6a3bbda83efb2b655a49 to your computer and use it in GitHub Desktop.
A slightly better refactoring for SLAP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SomeClass | |
{ | |
List<string> extractedValues = new List<string>(); | |
public void DoSomeWork(string inputFile) | |
{ | |
using (var file = OpenInputFile(inputFile)) | |
{ | |
while (MoreDataExists(file)) | |
{ | |
var nextLine = ReadNextLine(file); | |
ProcessLine(nextLine); | |
} | |
} | |
} | |
void ProcessLine(string inputLine) | |
{ | |
var inputData = GetFieldData(inputLine); | |
var desiredValue = ExtractDesiredValue(inputData); | |
AddValueToList(desiredValue); | |
} | |
StreamReader OpenInputFile(string inputFile) | |
{ | |
return new StreamReader(inputFile); | |
} | |
string[] GetFieldData(string inputLine) | |
{ | |
return inputLine.Split(','); | |
} | |
string ExtractDesiredValue(string[] fields) | |
{ | |
return fields[3]; | |
} | |
bool MoreDataExists(StreamReader reader) | |
{ | |
return reader.Peek() >= 0; | |
} | |
void AddValueToList(string value) | |
{ | |
extractedValues.Add(value); | |
} | |
string ReadNextLine(StreamReader reader) | |
{ | |
return reader.ReadLine(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment