BadScript 2
Loading...
Searching...
No Matches
BadNetInteropExtensions.cs
Go to the documentation of this file.
6
8
13{
15 protected override void AddExtensions(BadInteropExtensionProvider provider)
16 {
17 provider.RegisterObject<HttpResponseMessage>("Status", resp => (decimal)resp.StatusCode);
18 provider.RegisterObject<HttpResponseMessage>("Reason", resp => resp.ReasonPhrase ?? "");
19
20 provider.RegisterObject<HttpResponseMessage>("Headers",
21 resp =>
22 {
23 Dictionary<string, BadObject> v =
24 resp.Headers.ToDictionary(x => x.Key,
25 x => (BadObject)new BadArray(x.Value
26 .Select(y => (BadObject)y)
27 .ToList()
28 )
29 );
30
31 return new BadTable(v);
32 }
33 );
34 provider.RegisterObject<HttpResponseMessage>("Content", resp => BadObject.Wrap(resp.Content));
35
36 provider.RegisterObject<HttpContent>("ReadAsString",
37 c => new BadDynamicInteropFunction("ReadAsString",
40 )
41 )
42 );
43
44 provider.RegisterObject<HttpContent>("ReadAsArray",
45 c => new BadDynamicInteropFunction("ReadAsArray",
46 _ => Content_ReadAsArray(c),
48 )
49 );
50 }
51
57 private static BadTask Content_ReadAsString(HttpContent content)
58 {
59 Task<string> task = content.ReadAsStringAsync();
60
61 return new BadTask(BadTaskUtils.WaitForTask(task), "HttpContent.ReadAsString");
62 }
63
69 private static BadTask Content_ReadAsArray(HttpContent content)
70 {
71 Task<byte[]> task = content.ReadAsByteArrayAsync();
72
73 return new BadTask(BadTaskUtils.WaitForTask(task,
74 o => new BadArray(o.Select(x => (BadObject)(decimal)x)
75 .ToList()
76 )
77 ),
78 "HttpContent.ReadAsArray"
79 );
80 }
81}
Implements a Task Object.
Definition BadTask.cs:17
static BadInteropRunnable WaitForTask(System.Threading.Tasks.Task t)
Implements Extensions for the "Net" Api.
static BadTask Content_ReadAsArray(HttpContent content)
Reads the content as array.
static BadTask Content_ReadAsString(HttpContent content)
Reads the content as a string.
override void AddExtensions(BadInteropExtensionProvider provider)
Public Extension API for the BS2 Runtime.
void RegisterObject(Type t, string propName, BadObject obj)
Registers the specified extension for the specified type.
Implements a Dynamic List/Array for the BadScript Language.
Definition BadArray.cs:17
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
Implements a Table Structure for the BadScript Language.
Definition BadTable.cs:14
Helper Class that Builds a Native Class from a Prototype.
static BadClassPrototype GetNative(string name)
Returns a Native Class Prototype for the given Native Type.
Contains task/async Extensions and Integrations for the BadScript2 Runtime.
Contains Networking Extensions and APIs for the BadScript2 Runtime.
Definition BadNetApi.cs:6
Contains the Interop Function Classes for the BadScript2 Language.
Contains the Interop Abstractions and Implementations for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10