-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScriptingResult.cs
executable file
·66 lines (51 loc) · 1.61 KB
/
ScriptingResult.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
using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.CodeAnalysis.Scripting;
namespace Scripting
{
public enum ScriptingExecutionStatus { Ok, Error }
public class ScriptingResult
{
public ScriptingExecutionStatus Status { get; set; }
public string Result { get; set; }
public string ResultType { get; set; }
public List<ScriptingVariable> Variables { get; set; }
}
public class ScriptingVariable
{
public string Name { get; set; }
public string Type { get; set; }
public int Size { get; set; }
public string Value { get; set; }
internal ScriptingVariable(ScriptVariable v) : this(v.Type, v.Value)
{
Name = v.Name;
}
internal ScriptingVariable(object v) : this(v?.GetType(), v) { }
private ScriptingVariable(Type type, object value)
{
if (type == null)
return;
Type = Utils.GetTypeName(type);
if (value == null)
return;
// give arrays and collections a value representing their sizes, to create a useful state to display to a user
if (type.IsArray)
{
Size = ((Array)value).Length;
Value = Size + " objects";
}
else if (value is ICollection coll)
{
Size = coll.Count;
Value = coll.Count + " objects";
}
else
{
Size = 1;
Value = value.ToString();
}
}
}
}