private static T?ParseValue <T>(string value) where T : struct { if (typeof(T) == typeof(int)) { return(UsefulMath.TryParseInt(value) as T?); } if (typeof(T) == typeof(double)) { return(UsefulMath.TryParse(value) as T?); } if (typeof(T) == typeof(DateTime)) { return(UsefulMath.TryParseDateTime(value) as T?); } throw new NotImplementedException("Type not supported"); }
private DateTime?GetDirectoryDate(string directory) { if (directory.Length < 14) { return(null); } var year = UsefulMath.TryParseInt(directory.Substring(0, 4)); if (!year.HasValue) { return(null); } var month = UsefulMath.TryParseInt(directory.Substring(4, 2)); if (!month.HasValue) { return(null); } var day = UsefulMath.TryParseInt(directory.Substring(6, 2)); if (!day.HasValue) { return(null); } var hour = UsefulMath.TryParseInt(directory.Substring(8, 2)); if (!hour.HasValue) { return(null); } var minute = UsefulMath.TryParseInt(directory.Substring(10, 2)); if (!minute.HasValue) { return(null); } var second = UsefulMath.TryParseInt(directory.Substring(12, 2)); if (!second.HasValue) { return(null); } return(new DateTime(year.Value, month.Value, day.Value).AddHours(hour.Value).AddMinutes(minute.Value).AddSeconds(second.Value)); }