From 888a51c27d6bcc9c394603d1a3be60aa660ef062 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 27 Dec 2017 13:24:08 -0800 Subject: Better abstract extension factory, tuple to table creation and others --- .../BaseExtensionFactory.cs | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/WixToolset.Extensibility/BaseExtensionFactory.cs (limited to 'src/WixToolset.Extensibility/BaseExtensionFactory.cs') 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 @@ +// 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 WixToolset.Extensibility +{ + using System; + using System.Collections.Generic; + + /// + /// Base class for extension factories. + /// + public abstract class BaseExtensionFactory : IExtensionFactory + { + protected abstract IEnumerable ExtensionTypes { get; } + + public virtual bool TryCreateExtension(Type extensionType, out object extension) + { + extension = null; + + foreach (var type in this.ExtensionTypes) + { + if (extensionType.IsAssignableFrom(type)) + { + extension = Activator.CreateInstance(type); + break; + } + } + + return extension != null; + } + } +} -- cgit v1.2.3-55-g6feb