-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathScriptRunResult.cs
58 lines (49 loc) · 1.51 KB
/
ScriptRunResult.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
using ScriptingAbstractions;
using System;
using System.Collections.Generic;
using System.Linq;
namespace RoslynScripting
{
public class ScriptRunResult : IScriptRunResult
{
public bool IsSuccess { get; private set; }
public object ReturnValue { get; private set; }
public IEnumerable<Exception> Errors { get; private set; }
private ScriptRunResult(IEnumerable<Exception> exceptions)
{
this.IsSuccess = false;
this.ReturnValue = null;
this.Errors = exceptions;
}
private ScriptRunResult(Exception exception)
: this(new Exception[] { exception })
{
}
private ScriptRunResult(object ReturnValue)
{
this.IsSuccess = true;
this.ReturnValue = ReturnValue;
this.Errors = Enumerable.Empty<Exception>();
}
private ScriptRunResult()
{
}
public static ScriptRunResult Success(object ReturnValue = null)
{
return new ScriptRunResult()
{
IsSuccess = true,
ReturnValue = ReturnValue,
Errors = Enumerable.Empty<Exception>()
};
}
public static ScriptRunResult Failure(IEnumerable<Exception> Exceptions)
{
return new ScriptRunResult(Exceptions);
}
public static ScriptRunResult Failure(Exception exception)
{
return new ScriptRunResult(exception);
}
}
}