main
cs 39 lines 1.31 KB
Raw
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 ///
11 /// Implementations may request an IWixToolsetCoreServiceProvider at instantiation by having a single parameter constructor for it.
12 /// </summary>
13 public abstract class BaseExtensionFactory : IExtensionFactory
14 {
15 /// <summary>
16 /// The extension types of the WiX extension.
17 /// </summary>
18 protected abstract IReadOnlyCollection<Type> ExtensionTypes { get; }
19
20 /// <summary>
21 /// See <see cref="IExtensionFactory.TryCreateExtension(Type, out object)"/>
22 /// </summary>
23 public virtual bool TryCreateExtension(Type extensionType, out object extension)
24 {
25 extension = null;
26
27 foreach (var type in this.ExtensionTypes)
28 {
29 if (extensionType.IsAssignableFrom(type))
30 {
31 extension = Activator.CreateInstance(type);
32 break;
33 }
34 }
35
36 return extension != null;
37 }
38 }
39 }