-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (43 loc) · 1.35 KB
/
Program.cs
File metadata and controls
60 lines (43 loc) · 1.35 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
55
56
57
58
59
60
using System.Reflection;
using DouglasDwyer.CasCore;
namespace CasCoreTesting
{
internal class Program
{
static void Main(string[] args)
{
string filePath = Path.GetFullPath("PredicateStart.dll");
var policy = new CasPolicyBuilder() // Create a new, empty whitelist.
.WithDefaultSandbox() // Add all system types that are on the default whitelist
.Allow(new TypeBinding(typeof(char), DouglasDwyer.CasCore.Accessibility.Public))
.Allow(new TypeBinding(typeof(System.Boolean), DouglasDwyer.CasCore.Accessibility.Public)
.WithMethod(nameof(ToString), [], DouglasDwyer.CasCore.Accessibility.Public))
.Build();
var loadContext = new CasAssemblyLoader(policy);
var sandboxed = loadContext.LoadFromAssemblyPath(filePath);
Type? type= sandboxed.GetType("CSharpUnitProcessor.CSharpExpression");
if (type == null)
return;
var property = type.GetProperty("Result");
if (property == null)
return;
var ctor = type.GetConstructor(Type.EmptyTypes);
if (ctor == null)
return;
object obj = ctor.Invoke(null);
if (obj == null)
return;
var value = property.GetValue(obj)?.ToString();
if (value == null)
return;
Console.WriteLine(value);
}
}
}
//namespace CSharpUnitProcessor
//{
// public class CSharpExpression
// {
// public string Result => char.IsDigit('C').ToString();
// }
//}