Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An example of code meeting SLAP guidelines
public class SomeClass
{
string inputLine;
List<string> extractedValues = new List<string>();
public void DoSomeWork(string inputFile)
{
using (var file = OpenInputFile(inputFile))
{
while (MoreDataExists(file))
{
inputLine = ReadNextLine(file);
// do some work on the line
var inputData = GetFieldData();
var desiredValue = ExtractDesiredValue(inputData);
AddValueToList(desiredValue);
}
}
}
StreamReader OpenInputFile(string inputFile)
{
return new StreamReader(inputFile);
}
string[] GetFieldData()
{
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
You can’t perform that action at this time.