forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptPackManager.cs
More file actions
33 lines (28 loc) · 1.01 KB
/
ScriptPackManager.cs
File metadata and controls
33 lines (28 loc) · 1.01 KB
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
using System;
using System.Collections.Generic;
using ScriptCs.Contracts;
using ScriptCs.Exceptions;
namespace ScriptCs
{
public class ScriptPackManager : IScriptPackManager
{
private readonly IDictionary<Type, IScriptPackContext> _contexts = new Dictionary<Type, IScriptPackContext>();
public ScriptPackManager(IEnumerable<IScriptPackContext> contexts)
{
Guard.AgainstNullArgument("contexts", contexts);
foreach (var context in contexts)
{
_contexts[context.GetType()] = context;
}
}
public TContext Get<TContext>() where TContext : IScriptPackContext
{
var key = typeof(TContext);
if (!_contexts.ContainsKey(key))
{
throw new ScriptPackException(string.Format("Tried to resolve a script pack '{0}', but such script pack is not available in the current execution context.", key));
}
return (TContext)_contexts[key];
}
}
}