-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getting rid of metaprogramming package
- Loading branch information
Showing
20 changed files
with
75 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
...change.Precompilation.Metaprogramming/StackExchange.Precompilation.Metaprogramming.csproj
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
53 changes: 53 additions & 0 deletions
53
StackExchange.Precompilation/Metaprogramming/PrecompilationModuleLoader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace StackExchange.Precompilation | ||
{ | ||
internal class PrecompilationModuleLoader | ||
{ | ||
/// <summary>Fires when a <see cref="CompileModuleElement" /> cannot be resolved to an actual <see cref="System.Type" />.</summary> | ||
/// <remarks>Register the handlers before touching <see cref="LoadedModules" />.</remarks> | ||
public event Action<CompileModuleElement, Exception> ModuleInitializationFailed; | ||
|
||
/// <summary>Gets a cached collection of loaded modules.</summary> | ||
public ICollection<ICompileModule> LoadedModules => _loadedModules.Value; | ||
|
||
private readonly Lazy<ICollection<ICompileModule>> _loadedModules; | ||
private readonly PrecompilerSection _configuration; | ||
|
||
public PrecompilationModuleLoader(PrecompilerSection configuration) | ||
{ | ||
_configuration = configuration; | ||
_loadedModules = new Lazy<ICollection<ICompileModule>>(() => | ||
{ | ||
var result = new List<ICompileModule>(); | ||
if (_configuration == null || _configuration.CompileModules == null) | ||
{ | ||
return result; | ||
} | ||
|
||
foreach(var module in _configuration.CompileModules.Cast<CompileModuleElement>()) | ||
{ | ||
try | ||
{ | ||
var type = Type.GetType(module.Type, true); | ||
if (Activator.CreateInstance(type, true) is ICompileModule cm) | ||
{ | ||
result.Add(cm); | ||
} | ||
else | ||
{ | ||
throw new TypeLoadException($"{module.Type} is not an {nameof(ICompileModule)}."); | ||
} | ||
} | ||
catch(Exception ex) | ||
{ | ||
ModuleInitializationFailed?.Invoke(module, ex); | ||
} | ||
} | ||
return result; | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters