/// <summary> /// Try to get the datetime from an object. /// </summary> /// <param name="value">Object to try to parse.</param> /// <returns>The parsed datetime or null.</returns> public static DateTime?GetDateTimeNullable(object value) { DateTime currentDateTime = DateTime.UtcNow; DateTime newDateTime = DateTime.UtcNow; Boolean parse = DateTime.TryParse(HString.ToString(value), out newDateTime); return(parse ? (DateTime?)newDateTime : null); }
/// <summary> /// Safely trims a string from object and checks for special characters. /// </summary> /// <param name="value">The object to set string and trim.</param> /// <returns></returns> public static String CsvSafeTrim(Object value) { String newValue = HString.SafeTrim(value); if (newValue.IndexOfAny(new char[] { '"', ',' }) != -1) { newValue = String.Format("\"{0}\"", newValue.Replace("\"", "\"\"")); } return(newValue); }
/// <summary> /// Safely trims a string from object. /// </summary> /// <param name="value">The object to set string and trim.</param> /// <returns></returns> public static String SafeTrim(Object value) { return(value != null?HString.ToString(value).Trim() : String.Empty); }