main
cs 62 lines 1.99 KB
Raw
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 Example.Extension
4 {
5 using System;
6 using WixToolset.Extensibility;
7 using WixToolset.Extensibility.Data;
8 using WixToolset.Extensibility.Services;
9
10 internal class ExamplePreprocessorExtensionAndCommandLine : BasePreprocessorExtension, IExtensionCommandLine
11 {
12 private string exampleValueFromCommandLine;
13
14 public CommandLineHelp GetCommandLineHelp()
15 {
16 return new CommandLineHelp("Example command line extension", "example value", new[]
17 {
18 new CommandLineHelpSwitch("-example", "Sets an example value")
19 });
20 }
21
22 public ExamplePreprocessorExtensionAndCommandLine()
23 {
24 this.Prefixes = new[] { "ex" };
25 }
26
27 public void PreParse(ICommandLineContext context)
28 {
29 }
30
31 public bool TryParseArgument(ICommandLineParser parser, string argument)
32 {
33 if (parser.IsSwitch(argument) && argument.Substring(1).Equals("example", StringComparison.OrdinalIgnoreCase))
34 {
35 this.exampleValueFromCommandLine = parser.GetNextArgumentOrError(argument);
36 return true;
37 }
38
39 return false;
40 }
41
42 public bool TryParseCommand(ICommandLineParser parser, string argument, out ICommandLineCommand command)
43 {
44 command = null;
45 return false;
46 }
47
48 public void PostParse()
49 {
50 }
51
52 public override string GetVariableValue(string prefix, string name)
53 {
54 if (prefix == "ex" && "test".Equals(name, StringComparison.OrdinalIgnoreCase))
55 {
56 return String.IsNullOrWhiteSpace(this.exampleValueFromCommandLine) ? "(null)" : this.exampleValueFromCommandLine;
57 }
58
59 return null;
60 }
61 }
62 }