Created
June 12, 2012 13:46
-
-
Save ChrisMissal/2917597 to your computer and use it in GitHub Desktop.
Anti-Patterns and Worst Practices – Utils Class
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 static class Utils | |
{ | |
public static string CreateShippingMessage(DayOfWeek dayOfWeek, TimeSpan currentTime) | |
{ | |
var message = "Your package will be delivered "; | |
if (dayOfWeek >= DayOfWeek.Monday && dayOfWeek <= DayOfWeek.Thursday) | |
message += currentTime < new TimeSpan(0, 17, 45, 0) ? "today" : "tomorrow"; | |
else | |
message += "soon"; | |
return message; | |
} | |
} |
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 static class Utils | |
{ | |
private const string _filePath = "logfile.txt"; | |
public static void LogMessage(string message) | |
{ | |
using(TextWriter writer = File.AppendText(_filePath)) | |
{ | |
writer.WriteLine(message); | |
} | |
} | |
public static void LogException(Exception ex) | |
{ | |
using (TextWriter writer = File.AppendText(_filePath)) | |
{ | |
writer.WriteLine(ex.Message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment