| 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.Services; |
| 8 | |
| 9 | public class ExampleExtensionFactory : IExtensionFactory |
| 10 | { |
| 11 | private ExamplePreprocessorExtensionAndCommandLine preprocessorExtension; |
| 12 | |
| 13 | public ExampleExtensionFactory(IWixToolsetCoreServiceProvider serviceProvider) |
| 14 | { |
| 15 | this.ServiceProvider = serviceProvider; |
| 16 | } |
| 17 | |
| 18 | /// <summary> |
| 19 | /// This exists just to show it is possible to get a service provider to the extension factory. |
| 20 | /// </summary> |
| 21 | private IWixToolsetCoreServiceProvider ServiceProvider { get; } |
| 22 | |
| 23 | public bool TryCreateExtension(Type extensionType, out object extension) |
| 24 | { |
| 25 | if (extensionType == typeof(IExtensionCommandLine) || extensionType == typeof(IPreprocessorExtension)) |
| 26 | { |
| 27 | if (this.preprocessorExtension == null) |
| 28 | { |
| 29 | this.preprocessorExtension = new ExamplePreprocessorExtensionAndCommandLine(); |
| 30 | } |
| 31 | |
| 32 | extension = this.preprocessorExtension; |
| 33 | } |
| 34 | else if (extensionType == typeof(ICompilerExtension)) |
| 35 | { |
| 36 | extension = new ExampleCompilerExtension(); |
| 37 | } |
| 38 | else if (extensionType == typeof(IOptimizerExtension)) |
| 39 | { |
| 40 | extension = new ExampleOptimizerExtension(); |
| 41 | } |
| 42 | else if (extensionType == typeof(IExtensionData)) |
| 43 | { |
| 44 | extension = new ExampleExtensionData(); |
| 45 | } |
| 46 | else if (extensionType == typeof(IWindowsInstallerBackendBinderExtension)) |
| 47 | { |
| 48 | extension = new ExampleWindowsInstallerBackendExtension(); |
| 49 | } |
| 50 | else if (extensionType == typeof(IWindowsInstallerDecompilerExtension)) |
| 51 | { |
| 52 | extension = new ExampleWindowsInstallerDecompilerExtension(); |
| 53 | } |
| 54 | else |
| 55 | { |
| 56 | extension = null; |
| 57 | } |
| 58 | |
| 59 | return extension != null; |
| 60 | } |
| 61 | } |
| 62 | } |