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/WixToolset.Extensibility/BaseExtensionFactory.cs | |
| 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/WixToolset.Extensibility/BaseExtensionFactory.cs')
| -rw-r--r-- | src/WixToolset.Extensibility/BaseExtensionFactory.cs | 31 |
1 files changed, 31 insertions, 0 deletions
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 | } | ||
