blob: 1cc943e122f261156f25153add9b74c2ba8ee866 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
//-----------------------------------------------------------------------
// <copyright file="Trim.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.BuildTasks {
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
/// <summary>
/// Trims item identities.
/// </summary>
public class Trim : Task {
/// <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; }
/// <summary>
/// Gets or sets the characters that should be trimmed off if found at the end of items' ItemSpecs.
/// </summary>
public string EndCharacters { get; set; }
/// <summary>
/// Gets or sets the items with ItemSpec's to be trimmed.
/// </summary>
[Required]
public ITaskItem[] Inputs { get; set; }
/// <summary>
/// Gets or sets the items with trimmed ItemSpec strings.
/// </summary>
[Output]
public ITaskItem[] Outputs { get; set; }
/// <summary>
/// Executes this instance.
/// </summary>
/// <returns>A value indicating whether the task completed successfully.</returns>
public override bool Execute() {
this.Outputs = new ITaskItem[this.Inputs.Length];
for (int i = 0; i < this.Inputs.Length; i++) {
this.Outputs[i] = new TaskItem(this.Inputs[i]);
if (!string.IsNullOrEmpty(this.StartCharacters)) {
this.Outputs[i].ItemSpec = this.Outputs[i].ItemSpec.TrimStart(this.StartCharacters.ToCharArray());
}
if (!string.IsNullOrEmpty(this.EndCharacters)) {
this.Outputs[i].ItemSpec = this.Outputs[i].ItemSpec.TrimEnd(this.EndCharacters.ToCharArray());
}
}
return true;
}
}
}
|