diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-09-17 15:35:20 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-09-17 16:00:11 -0700 |
| commit | d3d3649a68cb1fa589fdd987a6690dbd5d671f0d (patch) | |
| tree | 44fe37ee352b7e3a355cc1e08b1d7d5988c14cc0 /src/WixToolset.BuildTasks/ReplaceString.cs | |
| parent | a62610d23d6feb98be3b1e529a4e81b19d77d9d8 (diff) | |
| download | wix-d3d3649a68cb1fa589fdd987a6690dbd5d671f0d.tar.gz wix-d3d3649a68cb1fa589fdd987a6690dbd5d671f0d.tar.bz2 wix-d3d3649a68cb1fa589fdd987a6690dbd5d671f0d.zip | |
Initial code commit
Diffstat (limited to 'src/WixToolset.BuildTasks/ReplaceString.cs')
| -rw-r--r-- | src/WixToolset.BuildTasks/ReplaceString.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/WixToolset.BuildTasks/ReplaceString.cs b/src/WixToolset.BuildTasks/ReplaceString.cs new file mode 100644 index 00000000..e5041923 --- /dev/null +++ b/src/WixToolset.BuildTasks/ReplaceString.cs | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | namespace WixToolset.BuildTasks | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using Microsoft.Build.Framework; | ||
| 7 | using Microsoft.Build.Utilities; | ||
| 8 | |||
| 9 | /// <summary> | ||
| 10 | /// Replaces occurances of OldValues with NewValues in String. | ||
| 11 | /// </summary> | ||
| 12 | public class ReplaceString : Task | ||
| 13 | { | ||
| 14 | /// <summary> | ||
| 15 | /// Text to operate on. | ||
| 16 | /// </summary> | ||
| 17 | [Output] | ||
| 18 | [Required] | ||
| 19 | public string Text { get; set; } | ||
| 20 | |||
| 21 | /// <summary> | ||
| 22 | /// List of old values to replace. | ||
| 23 | /// </summary> | ||
| 24 | [Required] | ||
| 25 | public string OldValue { get; set; } | ||
| 26 | |||
| 27 | /// <summary> | ||
| 28 | /// List of new values to replace old values with. If not specified, occurances of OldValue will be removed. | ||
| 29 | /// </summary> | ||
| 30 | public string NewValue { get; set; } | ||
| 31 | |||
| 32 | /// <summary> | ||
| 33 | /// Does the string replacement. | ||
| 34 | /// </summary> | ||
| 35 | /// <returns></returns> | ||
| 36 | public override bool Execute() | ||
| 37 | { | ||
| 38 | if (String.IsNullOrEmpty(this.Text)) | ||
| 39 | { | ||
| 40 | return true; | ||
| 41 | } | ||
| 42 | |||
| 43 | if (String.IsNullOrEmpty(this.OldValue)) | ||
| 44 | { | ||
| 45 | Log.LogError("OldValue must be specified"); | ||
| 46 | return false; | ||
| 47 | } | ||
| 48 | |||
| 49 | this.Text = this.Text.Replace(this.OldValue, this.NewValue); | ||
| 50 | |||
| 51 | return true; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | } | ||
