diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-12-27 13:24:08 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-12-27 13:24:08 -0800 |
| commit | 888a51c27d6bcc9c394603d1a3be60aa660ef062 (patch) | |
| tree | e339f1c7563ed2ee80fbff008d20255a88d476b4 /src | |
| parent | ed5fd9d8258a5c752cd37fe7702f3a0dc37052f7 (diff) | |
| download | wix-888a51c27d6bcc9c394603d1a3be60aa660ef062.tar.gz wix-888a51c27d6bcc9c394603d1a3be60aa660ef062.tar.bz2 wix-888a51c27d6bcc9c394603d1a3be60aa660ef062.zip | |
Better abstract extension factory, tuple to table creation and others
Diffstat (limited to 'src')
4 files changed, 67 insertions, 1 deletions
diff --git a/src/WixToolset.Extensibility/BaseCompilerExtension.cs b/src/WixToolset.Extensibility/BaseCompilerExtension.cs index 58efa37f..abe2f4a9 100644 --- a/src/WixToolset.Extensibility/BaseCompilerExtension.cs +++ b/src/WixToolset.Extensibility/BaseCompilerExtension.cs | |||
| @@ -31,7 +31,7 @@ namespace WixToolset.Extensibility | |||
| 31 | /// Gets the schema namespace for this extension. | 31 | /// Gets the schema namespace for this extension. |
| 32 | /// </summary> | 32 | /// </summary> |
| 33 | /// <value>Schema namespace supported by this extension.</value> | 33 | /// <value>Schema namespace supported by this extension.</value> |
| 34 | public XNamespace Namespace { get; protected set; } | 34 | public abstract XNamespace Namespace { get; } |
| 35 | 35 | ||
| 36 | /// <summary> | 36 | /// <summary> |
| 37 | /// Called at the beginning of the compilation of a source file. | 37 | /// Called at the beginning of the compilation of a source file. |
diff --git a/src/WixToolset.Extensibility/BaseExtensionData.cs b/src/WixToolset.Extensibility/BaseExtensionData.cs new file mode 100644 index 00000000..ddcec873 --- /dev/null +++ b/src/WixToolset.Extensibility/BaseExtensionData.cs | |||
| @@ -0,0 +1,25 @@ | |||
| 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.Extensibility | ||
| 4 | { | ||
| 5 | using WixToolset.Data; | ||
| 6 | |||
| 7 | /// <summary> | ||
| 8 | /// Base class for creating a resolver extension. | ||
| 9 | /// </summary> | ||
| 10 | public abstract class BaseExtensionData : IExtensionData | ||
| 11 | { | ||
| 12 | public virtual string DefaultCulture => null; | ||
| 13 | |||
| 14 | public virtual Intermediate GetLibrary(ITupleDefinitionCreator tupleDefinitions) | ||
| 15 | { | ||
| 16 | return null; | ||
| 17 | } | ||
| 18 | |||
| 19 | public virtual bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition) | ||
| 20 | { | ||
| 21 | tupleDefinition = null; | ||
| 22 | return false; | ||
| 23 | } | ||
| 24 | } | ||
| 25 | } | ||
diff --git a/src/WixToolset.Extensibility/BaseExtensionFactory.cs b/src/WixToolset.Extensibility/BaseExtensionFactory.cs new file mode 100644 index 00000000..2e7fdbb8 --- /dev/null +++ b/src/WixToolset.Extensibility/BaseExtensionFactory.cs | |||
| @@ -0,0 +1,31 @@ | |||
| 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.Extensibility | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | |||
| 8 | /// <summary> | ||
| 9 | /// Base class for extension factories. | ||
| 10 | /// </summary> | ||
| 11 | public abstract class BaseExtensionFactory : IExtensionFactory | ||
| 12 | { | ||
| 13 | protected abstract IEnumerable<Type> ExtensionTypes { get; } | ||
| 14 | |||
| 15 | public virtual bool TryCreateExtension(Type extensionType, out object extension) | ||
| 16 | { | ||
| 17 | extension = null; | ||
| 18 | |||
| 19 | foreach (var type in this.ExtensionTypes) | ||
| 20 | { | ||
| 21 | if (extensionType.IsAssignableFrom(type)) | ||
| 22 | { | ||
| 23 | extension = Activator.CreateInstance(type); | ||
| 24 | break; | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | return extension != null; | ||
| 29 | } | ||
| 30 | } | ||
| 31 | } | ||
diff --git a/src/WixToolset.Extensibility/BaseWindowsInstallerBackendExtension.cs b/src/WixToolset.Extensibility/BaseWindowsInstallerBackendExtension.cs index 0bcfce01..50e34288 100644 --- a/src/WixToolset.Extensibility/BaseWindowsInstallerBackendExtension.cs +++ b/src/WixToolset.Extensibility/BaseWindowsInstallerBackendExtension.cs | |||
| @@ -24,6 +24,11 @@ namespace WixToolset.Extensibility | |||
| 24 | /// </summary> | 24 | /// </summary> |
| 25 | protected IWindowsInstallerBackendHelper BackendHelper { get; private set; } | 25 | protected IWindowsInstallerBackendHelper BackendHelper { get; private set; } |
| 26 | 26 | ||
| 27 | /// <summary> | ||
| 28 | /// Optional table definitions to automatically map to tuples. | ||
| 29 | /// </summary> | ||
| 30 | protected virtual TableDefinition[] TableDefinitionsForTuples { get; } | ||
| 31 | |||
| 27 | public virtual void PreBackendBind(IBindContext context) | 32 | public virtual void PreBackendBind(IBindContext context) |
| 28 | { | 33 | { |
| 29 | this.Context = context; | 34 | this.Context = context; |
| @@ -43,6 +48,11 @@ namespace WixToolset.Extensibility | |||
| 43 | 48 | ||
| 44 | public virtual bool TryAddTupleToOutput(IntermediateTuple tuple, Output output) | 49 | public virtual bool TryAddTupleToOutput(IntermediateTuple tuple, Output output) |
| 45 | { | 50 | { |
| 51 | if (this.TableDefinitionsForTuples != null) | ||
| 52 | { | ||
| 53 | return this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(tuple, output, this.TableDefinitionsForTuples); | ||
| 54 | } | ||
| 55 | |||
| 46 | return false; | 56 | return false; |
| 47 | } | 57 | } |
| 48 | 58 | ||
