aboutsummaryrefslogtreecommitdiff
path: root/src/test/TestData/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs
blob: 53394ea3bde7aad161efc8d6298d6c55408adb42 (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
// 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.

namespace Example.Extension
{
    using System;
    using System.Collections.Generic;
    using WixToolset.Extensibility;
    using WixToolset.Extensibility.Services;

    internal class ExamplePreprocessorExtensionAndCommandLine : BasePreprocessorExtension, IExtensionCommandLine
    {
        private string exampleValueFromCommandLine;

        public IEnumerable<ExtensionCommandLineSwitch> CommandLineSwitches => throw new NotImplementedException();

        public ExamplePreprocessorExtensionAndCommandLine()
        {
            this.Prefixes = new[] { "ex" };
        }

        public void PreParse(ICommandLineContext context)
        {
        }

        public bool TryParseArgument(IParseCommandLine parseCommandLine, string arg)
        {
            if (parseCommandLine.IsSwitch(arg) && arg.Substring(1).Equals("example", StringComparison.OrdinalIgnoreCase))
            {
                parseCommandLine.GetNextArgumentOrError(ref this.exampleValueFromCommandLine);
                return true;
            }

            return false;
        }

        public override string GetVariableValue(string prefix, string name)
        {
            if (prefix == "ex" && "test".Equals(name, StringComparison.OrdinalIgnoreCase))
            {
                return String.IsNullOrWhiteSpace(this.exampleValueFromCommandLine) ? "(null)" : this.exampleValueFromCommandLine;
            }

            return null;
        }
    }
}