File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Code/MethodSystem/Methods/HTTPMethods Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments