static DateTime CoerceToDateTime(object value) { return(CoerceTo <DateTime> .Value(value) .Type <DateTime>(v => v) .Type <double>(v => DateTime.FromOADate(v)) .Type <int>(v => DateTime.FromOADate(v)) .ElseThrow()); }
static string FormatExceptionMessage(Exception exception) { if (exception == null) { return(null); } var inners = CoerceTo <string[]> .Value(exception) .Type <AggregateException>(a => a.InnerExceptions.Select(FormatExceptionMessage).ToArray()) .Else(e => new[] { FormatExceptionMessage(e.InnerException) }); var aggregate = exception as AggregateException; if (aggregate != null) { if (aggregate.Message == "One or more errors occurred.") { return(inners.JoinStrings(Environment.NewLine)); } } return(exception.Message + Environment.NewLine + inners.Select(i => Indent(i)).JoinStrings(Environment.NewLine)); }