-
Notifications
You must be signed in to change notification settings - Fork 368
Expand file tree
/
Copy pathScriptExecutorExtensions.cs
More file actions
54 lines (42 loc) · 1.76 KB
/
ScriptExecutorExtensions.cs
File metadata and controls
54 lines (42 loc) · 1.76 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ScriptCs.Contracts;
namespace ScriptCs
{
public static class ScriptExecutorExtensions
{
public static void ImportNamespaces(this IScriptExecutor executor, params Type[] typesFromReferencedAssembly)
{
Guard.AgainstNullArgument("executor", executor);
Guard.AgainstNullArgument("typesFromReferencedAssembly", typesFromReferencedAssembly);
var namespaces = typesFromReferencedAssembly.Select(t => t.Namespace);
executor.ImportNamespaces(namespaces.ToArray());
}
public static void ImportNamespace<T>(this IScriptExecutor executor)
{
Guard.AgainstNullArgument("executor", executor);
executor.ImportNamespaces(typeof(T));
}
public static void AddReferences(this IScriptExecutor executor, params Type[] typesFromReferencedAssembly)
{
Guard.AgainstNullArgument("executor", executor);
Guard.AgainstNullArgument("typeFromReferencedAssembly", typesFromReferencedAssembly);
var paths = typesFromReferencedAssembly.Select(t => t.Assembly.Location);
executor.AddReferences(paths.ToArray());
}
public static void AddReference<T>(this IScriptExecutor executor)
{
Guard.AgainstNullArgument("executor", executor);
executor.AddReferences(typeof(T));
}
public static void AddReferenceAndImportNamespaces(this IScriptExecutor executor, Type[] types)
{
Guard.AgainstNullArgument("executor", executor);
executor.AddReferences(types);
executor.ImportNamespaces(types);
}
}
}