2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / nunit24 / NUnitCore / core / TextCapture.cs
blob705f8196e4250ed386f62443a32d4894d5f7cdd2
1 // ****************************************************************
2 // Copyright 2008, Charlie Poole
3 // This is free software licensed under the NUnit license. You may
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4
5 // ****************************************************************
7 using System.IO;
9 namespace NUnit.Core
11 /// <summary>
12 /// Abstract base for classes that capture text output
13 /// and redirect it to a TextWriter.
14 /// </summary>
15 public abstract class TextCapture
17 #region Private Fields
18 /// <summary>
19 /// True if capture is enabled
20 /// </summary>
21 private bool enabled;
23 /// <summary>
24 /// The TextWriter to which text is redirected
25 /// </summary>
26 private TextWriter writer;
27 #endregion
29 #region Properties
30 /// <summary>
31 /// The TextWriter to which text is redirected
32 /// </summary>
33 public TextWriter Writer
35 get { return writer; }
36 set
38 writer = value;
40 if (writer != null && enabled)
41 StartCapture();
45 /// <summary>
46 /// Controls whether text is captured or not
47 /// </summary>
48 public bool Enabled
50 get { return enabled; }
51 set
53 if (enabled != value)
55 if (writer != null && enabled)
56 StopCapture();
58 enabled = value;
60 if (writer != null && enabled && DefaultThreshold != "Off")
61 StartCapture();
66 /// <summary>
67 /// Returns the default threshold value, which represents
68 /// the degree of verbosity of the output text stream.
69 /// Returns "None" in the base class. Derived classes that
70 /// support verbosity levels should override it.
71 /// </summary>
72 public virtual string DefaultThreshold
74 get { return "None"; }
76 #endregion
78 #region Abstract Members
79 /// <summary>
80 /// Override this to perform whatever actions are needed
81 /// to start capturing text and sending it to the Writer.
82 /// </summary>
83 protected abstract void StartCapture();
85 /// <summary>
86 /// Override this to perform whatever actions are needed
87 /// to flush remaining output and stop capturing text.
88 /// The Writer should not be changed, allowing capture
89 /// to be restarted at a future point.
90 /// </summary>
91 protected abstract void StopCapture();
92 #endregion