From 95f2f4425b900374c7d7b583ae810b096121b3c4 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 2 Dec 2017 00:46:11 -0800 Subject: Implement support for IExtensionCommandLine and IPreprocessorExtension --- .../Example.Extension/ExampleExtensionFactory.cs | 11 ++++- .../ExamplePreprocessorExtension.cs | 55 ---------------------- .../ExamplePreprocessorExtensionAndCommandLine.cs | 46 ++++++++++++++++++ 3 files changed, 55 insertions(+), 57 deletions(-) delete mode 100644 src/test/Example.Extension/ExamplePreprocessorExtension.cs create mode 100644 src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs (limited to 'src/test/Example.Extension') diff --git a/src/test/Example.Extension/ExampleExtensionFactory.cs b/src/test/Example.Extension/ExampleExtensionFactory.cs index 9539ee85..b91d06e9 100644 --- a/src/test/Example.Extension/ExampleExtensionFactory.cs +++ b/src/test/Example.Extension/ExampleExtensionFactory.cs @@ -7,11 +7,18 @@ namespace Example.Extension public class ExampleExtensionFactory : IExtensionFactory { + private ExamplePreprocessorExtensionAndCommandLine preprocessorExtension; + public bool TryCreateExtension(Type extensionType, out object extension) { - if (extensionType == typeof(IPreprocessorExtension)) + if (extensionType == typeof(IExtensionCommandLine) || extensionType == typeof(IPreprocessorExtension)) { - extension = new ExamplePreprocessorExtension(); + if (preprocessorExtension == null) + { + preprocessorExtension = new ExamplePreprocessorExtensionAndCommandLine(); + } + + extension = preprocessorExtension; } else if (extensionType == typeof(ICompilerExtension)) { diff --git a/src/test/Example.Extension/ExamplePreprocessorExtension.cs b/src/test/Example.Extension/ExamplePreprocessorExtension.cs deleted file mode 100644 index c16c8b5a..00000000 --- a/src/test/Example.Extension/ExamplePreprocessorExtension.cs +++ /dev/null @@ -1,55 +0,0 @@ -// 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.Xml.Linq; - using WixToolset.Data; - using WixToolset.Extensibility; - - internal class ExamplePreprocessorExtension : IPreprocessorExtension - { - public ExamplePreprocessorExtension() - { - } - - public IPreprocessorCore Core { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - - public string[] Prefixes => throw new NotImplementedException(); - - public string EvaluateFunction(string prefix, string function, string[] args) - { - throw new NotImplementedException(); - } - - public void Finish() - { - throw new NotImplementedException(); - } - - public string GetVariableValue(string prefix, string name) - { - throw new NotImplementedException(); - } - - public void Initialize() - { - throw new NotImplementedException(); - } - - public void PreprocessDocument(XDocument document) - { - throw new NotImplementedException(); - } - - public string PreprocessParameter(string name) - { - throw new NotImplementedException(); - } - - public bool ProcessPragma(SourceLineNumber sourceLineNumbers, string prefix, string pragma, string args, XContainer parent) - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs b/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs new file mode 100644 index 00000000..53394ea3 --- /dev/null +++ b/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs @@ -0,0 +1,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 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; + } + } +} \ No newline at end of file -- cgit v1.2.3-55-g6feb