Skip to content

Commit a883ea9

Browse files
committed
Revert "Delete ParseJSONMethod.cs"
This reverts commit 7b03c15.
1 parent 993e72b commit a883ea9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Newtonsoft.Json.Linq;
2+
using SER.Code.ArgumentSystem.Arguments;
3+
using SER.Code.ArgumentSystem.BaseArguments;
4+
using SER.Code.Helpers.Exceptions;
5+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
6+
using SER.Code.MethodSystem.MethodDescriptors;
7+
8+
namespace SER.Code.MethodSystem.Methods.HTTPMethods;
9+
10+
// ReSharper disable once InconsistentNaming
11+
public class ParseJSONMethod : ReferenceReturningMethod<JObject>, ICanError
12+
{
13+
public override string Description => "Parses a provided value into a JSON object.";
14+
15+
public string[] ErrorReasons { get; } =
16+
[
17+
"Provided value is not parsable as a JSON object."
18+
];
19+
20+
public override Argument[] ExpectedArguments { get; } =
21+
[
22+
new TextArgument("string representation of JSON object")
23+
];
24+
25+
public override void Execute()
26+
{
27+
var valueToParse = Args.GetText("string representation of JSON object");
28+
29+
try
30+
{
31+
ReturnValue = JObject.Parse(valueToParse);
32+
}
33+
catch
34+
{
35+
throw new ScriptRuntimeError(this, ErrorReasons[0]);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)