/// <summary> /// Renders the object <paramref name="obj"/>, which must be derived from System.Exception, to a string. /// </summary> /// <param name="obj">An Exception to be rendered as text.</param> /// <param name="writer">TextWriter to which the rendered text is written.</param> public void RenderObject(object obj, TextWriter writer) { Exception ex = (Exception)obj; writer.WriteLine("Exception type: {0}", ex.GetType()); if (ex.Message != null) { writer.WriteLine("Message: {0}", ex.Message); } if (ex.Source != null) { writer.WriteLine("Source: {0}", ex.Source); } if (ex.StackTrace != null) { writer.WriteLine("StackTrace:\n{0}", ex.StackTrace); } if (ex.Data != null && ex.Data.Count > 0) { foreach (DictionaryEntry entry in ex.Data) { writer.WriteLine("{0}: {1}", entry.Key, entry.Value); } } if (ex.InnerException != null) { writer.Write("\nInner "); // The inner exception type may have a custom renderer. RendererMap.FindAndRender(ex.InnerException, writer); } }
/// <summary> /// Render the enumerator argument into a string /// </summary> /// <param name="enumerator">the enumerator to render</param> /// <param name="writer">The writer to render to</param> /// <remarks> /// <para> /// Rendered as an open brace, followed by a comma /// separated list of the elements (using the appropriate /// renderer), followed by a close brace. For example: /// <c>{a, b, c}</c>. /// </para> /// </remarks> private void RenderEnumerator(IEnumerator enumerator, TextWriter writer) { writer.Write("{"); if (enumerator != null && enumerator.MoveNext()) { RendererMap.FindAndRender(enumerator.Current, writer); while (enumerator.MoveNext()) { writer.Write(", "); RendererMap.FindAndRender(enumerator.Current, writer); } } writer.Write("}"); }
/// <summary> /// Render the array argument into a string /// </summary> /// <param name="array">the array to render</param> /// <param name="writer">The writer to render to</param> /// <remarks> /// <para> /// For a one dimensional array this is the /// array type name, an open brace, followed by a comma /// separated list of the elements (using the appropriate /// renderer), followed by a close brace. For example: /// <c>int[] {1, 2, 3}</c>. /// </para> /// <para> /// If the array is not one dimensional the /// <c>Array.ToString()</c> is returned. /// </para> /// </remarks> private void RenderArray(Array array, TextWriter writer) { if (array.Rank != 1) { writer.Write(array.ToString()); } else { writer.Write(array.GetType().Name + " {"); int len = array.Length; if (len > 0) { RendererMap.FindAndRender(array.GetValue(0), writer); for (int i = 1; i < len; i++) { writer.Write(", "); RendererMap.FindAndRender(array.GetValue(i), writer); } } writer.Write("}"); } }
/// <summary> /// Render the DictionaryEntry argument into a string /// </summary> /// <param name="entry">the DictionaryEntry to render</param> /// <param name="writer">The writer to render to</param> /// <remarks> /// <para> /// Render the key, an equals sign ('='), and the value (using the appropriate /// renderer). For example: <c>key=value</c>. /// </para> /// </remarks> private void RenderDictionaryEntry(DictionaryEntry entry, TextWriter writer) { RendererMap.FindAndRender(entry.Key, writer); writer.Write("="); RendererMap.FindAndRender(entry.Value, writer); }