diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-10-10 14:33:18 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-10-10 14:33:18 -0700 |
commit | 8ee4140ede197371e727874fea2579aac42df713 (patch) | |
tree | 387127cccb1232fbbf1c435698d4e0fc5d6709fa /src/DotNetOpenAuth.BuildTasks/Trim.cs | |
parent | 525c175898c8b98381b217f8d6ef49594da41dcc (diff) | |
download | DotNetOpenAuth-8ee4140ede197371e727874fea2579aac42df713.zip DotNetOpenAuth-8ee4140ede197371e727874fea2579aac42df713.tar.gz DotNetOpenAuth-8ee4140ede197371e727874fea2579aac42df713.tar.bz2 |
Fine tuned the project template generation.
Diffstat (limited to 'src/DotNetOpenAuth.BuildTasks/Trim.cs')
-rw-r--r-- | src/DotNetOpenAuth.BuildTasks/Trim.cs | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/DotNetOpenAuth.BuildTasks/Trim.cs b/src/DotNetOpenAuth.BuildTasks/Trim.cs index 1cc943e..972b87d 100644 --- a/src/DotNetOpenAuth.BuildTasks/Trim.cs +++ b/src/DotNetOpenAuth.BuildTasks/Trim.cs @@ -9,10 +9,16 @@ namespace DotNetOpenAuth.BuildTasks { using Microsoft.Build.Utilities; /// <summary> - /// Trims item identities. + /// Trims item identities or metadata. /// </summary> public class Trim : Task { /// <summary> + /// Gets or sets the name of the metadata to trim. Leave empty or null to operate on itemspec. + /// </summary> + /// <value>The name of the metadata.</value> + public string MetadataName { get; set; } + + /// <summary> /// Gets or sets the characters that should be trimmed off if found at the start of items' ItemSpecs. /// </summary> public string StartCharacters { get; set; } @@ -23,6 +29,11 @@ namespace DotNetOpenAuth.BuildTasks { public string EndCharacters { get; set; } /// <summary> + /// Gets or sets the substring that should be trimmed along with everything that appears after it. + /// </summary> + public string AllAfter { get; set; } + + /// <summary> /// Gets or sets the items with ItemSpec's to be trimmed. /// </summary> [Required] @@ -42,11 +53,23 @@ namespace DotNetOpenAuth.BuildTasks { this.Outputs = new ITaskItem[this.Inputs.Length]; for (int i = 0; i < this.Inputs.Length; i++) { this.Outputs[i] = new TaskItem(this.Inputs[i]); + string value = string.IsNullOrEmpty(this.MetadataName) ? this.Outputs[i].ItemSpec : this.Outputs[i].GetMetadata(this.MetadataName); if (!string.IsNullOrEmpty(this.StartCharacters)) { - this.Outputs[i].ItemSpec = this.Outputs[i].ItemSpec.TrimStart(this.StartCharacters.ToCharArray()); + value = value.TrimStart(this.StartCharacters.ToCharArray()); } if (!string.IsNullOrEmpty(this.EndCharacters)) { - this.Outputs[i].ItemSpec = this.Outputs[i].ItemSpec.TrimEnd(this.EndCharacters.ToCharArray()); + value = value.TrimEnd(this.EndCharacters.ToCharArray()); + } + if (!string.IsNullOrEmpty(this.AllAfter)) { + int index = value.IndexOf(this.AllAfter); + if (index >= 0) { + value = value.Substring(0, index); + } + } + if (string.IsNullOrEmpty(this.MetadataName)) { + this.Outputs[i].ItemSpec = value; + } else { + this.Outputs[i].SetMetadata(this.MetadataName, value); } } |