This repository has been archived by the owner on Aug 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
BaseTargetLoaderPlugin.cs
75 lines (69 loc) · 3.59 KB
/
BaseTargetLoaderPlugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace LinFu.Reflection.Plugins
{
/// <summary>
/// A plugin class that provides the basic implementation
/// for plugins that work with <see cref="IAssemblyTargetLoader{TTarget}"/> instances.
/// </summary>
/// <typeparam name="TTarget">The target type being configured.</typeparam>
/// <typeparam name="TAssembly">The assembly type.</typeparam>
/// <typeparam name="TType">The input type.</typeparam>
public abstract class BaseTargetLoaderPlugin<TTarget, TAssembly, TType> : BaseLoaderPlugin<TTarget>,
IInitialize<ILoader<TTarget>>
{
private readonly ITypeExtractor<TAssembly, TType> _typeExtractor;
private readonly IAssemblyTargetLoader<TTarget, TAssembly, TType> _assemblyLoader;
/// <summary>
/// Initializes a new instance of the <see cref="BaseTargetLoaderPlugin{TTarget,TAssembly,TType}"/> class.
/// </summary>
/// <param name="typeExtractor">The type extractor that will pull the types out of the current assembly.</param>
/// <param name="assemblyLoader">The assembly loader that will load the current assembly into memory.</param>
protected BaseTargetLoaderPlugin(ITypeExtractor<TAssembly, TType> typeExtractor, IAssemblyTargetLoader<TTarget, TAssembly, TType> assemblyLoader)
{
_typeExtractor = typeExtractor;
_assemblyLoader = assemblyLoader;
}
/// <summary>
/// Searches the loader for an <see cref="IAssemblyTargetLoader{T}"/>
/// instance and uses its derived classes to initialize
/// the assembly target loader.
/// </summary>
/// <param name="source">The <see cref="ILoader{TTarget}"/> instance that will hold the plugin.</param>
public void Initialize(ILoader<TTarget> source)
{
Initialize(source, _assemblyLoader);
}
/// <summary>
/// Initializes the <paramref name="loader"/> instance
/// with the given <paramref name="assemblyLoader"/> instance.
/// </summary>
/// <param name="loader">The loader being configured.</param>
/// <param name="assemblyLoader">The assembly loader that will load the types into the loader itself.</param>
protected abstract void Initialize(ILoader<TTarget> loader,
IAssemblyTargetLoader<TTarget, TAssembly, TType> assemblyLoader);
}
/// <summary>
/// A plugin class that provides the basic implementation
/// for plugins that work with <see cref="IAssemblyTargetLoader{TTarget}"/> instances.
/// </summary>
public abstract class BaseTargetLoaderPlugin<TTarget> : BaseTargetLoaderPlugin<TTarget, Assembly, Type>
{
/// <summary>
/// Initializes a new instance of the <see cref="BaseTargetLoaderPlugin{TTarget,TAssembly,TType}"/> class.
/// </summary>
protected BaseTargetLoaderPlugin() : this(new TypeExtractor())
{
}
/// <summary>
/// Initializes a new instance of the <see cref="BaseTargetLoaderPlugin{TTarget,TAssembly,TType}"/> class.
/// </summary>
/// <param name="typeExtractor">The type extractor that will pull the types out of the current assembly.</param>
protected BaseTargetLoaderPlugin(ITypeExtractor<Assembly, Type> typeExtractor) :
base(typeExtractor, new AssemblyTargetLoader<TTarget, Assembly, Type>(typeExtractor, new AssemblyLoader()))
{
}
}
}