@joebigelow / wix-1 / commits / 888a51c2

Better abstract extension factory, tuple to table creation and others

Rob Mensching committed Dec 27, 2017 at 13:24 UTC 888a51c27d6bcc9c394603d1a3be60aa660ef062
4 files changed +67 -1
src/WixToolset.Extensibility/BaseCompilerExtension.cs
+1 -1
@@ -31,7 +31,7 @@ namespace WixToolset.Extensibility
31 /// Gets the schema namespace for this extension.
32 /// </summary>
33 /// <value>Schema namespace supported by this extension.</value>
34 - public XNamespace Namespace { get; protected set; }
34 + public abstract XNamespace Namespace { get; }
35
36 /// <summary>
37 /// Called at the beginning of the compilation of a source file.
src/WixToolset.Extensibility/BaseExtensionData.cs new
+25
@@ -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 +}
src/WixToolset.Extensibility/BaseExtensionFactory.cs new
+31
@@ -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 +}
src/WixToolset.Extensibility/BaseWindowsInstallerBackendExtension.cs
+10
@@ -24,6 +24,11 @@ namespace WixToolset.Extensibility
24 /// </summary>
25 protected IWindowsInstallerBackendHelper BackendHelper { get; private set; }
26
27 + /// <summary>
28 + /// Optional table definitions to automatically map to tuples.
29 + /// </summary>
30 + protected virtual TableDefinition[] TableDefinitionsForTuples { get; }
31 +
32 public virtual void PreBackendBind(IBindContext context)
33 {
34 this.Context = context;
@@ -43,6 +48,11 @@ namespace WixToolset.Extensibility
48
49 public virtual bool TryAddTupleToOutput(IntermediateTuple tuple, Output output)
50 {
51 + if (this.TableDefinitionsForTuples != null)
52 + {
53 + return this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(tuple, output, this.TableDefinitionsForTuples);
54 + }
55 +
56 return false;
57 }
58