diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2011-10-09 15:58:19 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2011-10-09 15:58:19 -0700 |
commit | 378db560d5784562e0fe5e494943fa2dfa68f036 (patch) | |
tree | 5f4a04a096e36daaf99d70df0eb12e175fe97bf0 /src/DotNetOpenAuth.BuildTasks/RegexFileReplace.cs | |
parent | 8d54af386194defdc1d26fded5b7c60ddd78904e (diff) | |
download | DotNetOpenAuth-378db560d5784562e0fe5e494943fa2dfa68f036.zip DotNetOpenAuth-378db560d5784562e0fe5e494943fa2dfa68f036.tar.gz DotNetOpenAuth-378db560d5784562e0fe5e494943fa2dfa68f036.tar.bz2 |
Fixed up XAML and ASPX references to the unified DotNetOpenAuth assembly.
Diffstat (limited to 'src/DotNetOpenAuth.BuildTasks/RegexFileReplace.cs')
-rw-r--r-- | src/DotNetOpenAuth.BuildTasks/RegexFileReplace.cs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.BuildTasks/RegexFileReplace.cs b/src/DotNetOpenAuth.BuildTasks/RegexFileReplace.cs new file mode 100644 index 0000000..294a859 --- /dev/null +++ b/src/DotNetOpenAuth.BuildTasks/RegexFileReplace.cs @@ -0,0 +1,55 @@ +//----------------------------------------------------------------------- +// <copyright file="RegexFileReplace.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.BuildTasks { + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Reflection; + using System.Text; + using Microsoft.Build.BuildEngine; + using Microsoft.Build.Framework; + using Microsoft.Build.Utilities; + using System.Text.RegularExpressions; + + public class RegexFileReplace : Task { + /// <summary> + /// Gets or sets the set of files to search. + /// </summary> + [Required] + public ITaskItem[] Files { get; set; } + + /// <summary> + /// Gets or sets the files to save the changed files to. This may be the same as the input files to make the change in place. + /// </summary> + public ITaskItem[] OutputFiles { get; set; } + + public string Pattern { get; set; } + + public string Replacement { get; set; } + + /// <summary> + /// Executes this instance. + /// </summary> + public override bool Execute() { + if (this.OutputFiles == null || this.OutputFiles.Length == 0) { + this.OutputFiles = this.Files; + } + + foreach (var file in this.Files) { + string[] lines = File.ReadAllLines(file.ItemSpec); + for (int i = 0; i < lines.Length; i++) { + lines[i] = Regex.Replace(lines[i], this.Pattern, this.Replacement); + } + + File.WriteAllLines(file.ItemSpec, lines); + } + + return !this.Log.HasLoggedErrors; + } + } +} |