// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#if NET_2_0
using System;
using System.Collections;
public override bool Execute ()
{
- if (file == null)
- throw new ArgumentNullException ("file", "File TaskItem must be set.");
- if (file.ItemSpec == String.Empty)
- throw new ArgumentException ("File must be specified in ItemSpec.");
try {
- streamWriter = new StreamWriter (file.GetMetadata ("FullPath"), !overwrite);
- foreach (ITaskItem line in lines) {
- streamWriter.WriteLine (line);
+ string fullpath = file.GetMetadata ("FullPath");
+ if (lines == null && overwrite) {
+ System.IO.File.Delete (fullpath);
+ return true;
}
+
+ using (streamWriter = new StreamWriter (fullpath, !overwrite)) {
+ if (lines != null)
+ foreach (ITaskItem line in lines)
+ streamWriter.WriteLine (line);
+ }
+
return true;
}
catch (Exception ex) {
[Required]
public ITaskItem File {
- get {
- return file;
- }
- set {
- file = value;
- }
+ get { return file; }
+ set { file = value; }
}
- [Required]
public ITaskItem[] Lines {
- get {
- return lines;
- }
- set {
- lines = value;
- }
+ get { return lines; }
+ set { lines = value; }
}
public bool Overwrite {
- get {
- return overwrite;
- }
- set {
- overwrite = value;
- }
+ get { return overwrite; }
+ set { overwrite = value; }
}
}
}
-#endif
\ No newline at end of file