Trace.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using MatrixIO.IO;
  2. namespace System.Diagnostics
  3. {
  4. internal static class Trace
  5. {
  6. public static void WriteLine(object value, string category = null)
  7. {
  8. if (PortabilityFactory.Current != null) PortabilityFactory.Current.TraceWriteLine(value, category);
  9. else Debug.WriteLine(new String(' ', _indentLevel * 2) + (category == null ? value : category + ": " + value));
  10. }
  11. public static void Assert(bool condition, string message = null)
  12. {
  13. if (PortabilityFactory.Current != null) PortabilityFactory.Current.TraceAssert(condition, message);
  14. else Debug.Assert(condition, message);
  15. }
  16. private static int _indentLevel = 0;
  17. public static int IndentLevel
  18. {
  19. get
  20. {
  21. return PortabilityFactory.Current != null ? PortabilityFactory.Current.TraceIndentLevel : _indentLevel;
  22. }
  23. set
  24. {
  25. if (PortabilityFactory.Current != null) PortabilityFactory.Current.TraceIndentLevel = value < 0 ? 0 : value;
  26. else _indentLevel = value < 0 ? 0 : value;
  27. }
  28. }
  29. public static void Indent()
  30. {
  31. IndentLevel++;
  32. }
  33. public static void Unindent()
  34. {
  35. IndentLevel--;
  36. }
  37. }
  38. }