public static string ComplexObjectToPseudoCode(object val, int indent = 0) { string retval = PlainObjectToCode(val); if (retval != null) { return(retval); } else if (val is Array) { return("new[] " + FormatEnumerable((IEnumerable)val)); } else if (val is IEnumerable) { return(FormatEnumerable((IEnumerable)val)); } else if (val is Expression) { return(ExpressionToCode.ToCode((Expression)val)); } else if (val.GetType().GuessTypeClass() == ReflectionHelpers.TypeClass.AnonymousType) { var type = val.GetType(); return("\n" + new string(' ', indent * 2) + "new {" + String.Join( "", type.GetProperties() .Select( pi => "\n" + new string(' ', indent * 2 + 2) + pi.Name + " = " + ComplexObjectToPseudoCode(pi.GetValue(val, null), indent + 2) + ",") ) + "\n" + new string(' ', indent * 2) + "}"); } else { return(val.ToString()); } }
static Exception Err(Expression <Func <bool> > assertion, string msg, Exception innerException) { return(UnitTestingFailure.AssertionExceptionFactory(ExpressionToCode.AnnotatedToCode(assertion.Body, msg, true), innerException)); }