public
Created

Anti-Patterns and Worst Practices – Utils Class

  • Download Gist
MoreUtils.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12
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;
}
}
Utils.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
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);
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.