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 provider.RegisterObject<HttpResponseMessage>(
20 "Headers",
21 resp =>
22 {
23 Dictionary<string, BadObject> v = resp.Headers.ToDictionary(
24 x => x.Key,
25 x => (BadObject)new BadArray(x.Value.Select(y => (BadObject)y).ToList())
26 );
27
28 return new BadTable(v);
29 }
30 );
31 provider.RegisterObject<HttpResponseMessage>("Content", resp => BadObject.Wrap(resp.Content));
32
33 provider.RegisterObject<HttpContent>(
34 "ReadAsString",
36 "ReadAsString",
39 )
40 );
41 provider.RegisterObject<HttpContent>(
42 "ReadAsArray",
44 "ReadAsArray",
45 _ => Content_ReadAsArray(c),
47 )
48 );
49 }
50
56 private static BadTask Content_ReadAsString(HttpContent content)
57 {
58 Task<string> task = content.ReadAsStringAsync();
59
60 return new BadTask(BadTaskUtils.WaitForTask(task), "HttpContent.ReadAsString");
61 }
62
68 private static BadTask Content_ReadAsArray(HttpContent content)
69 {
70 Task<byte[]> task = content.ReadAsByteArrayAsync();
71
72 return new BadTask(
74 task,
75 o => new BadArray(o.Select(x => (BadObject)(decimal)x).ToList())
76 ),
77 "HttpContent.ReadAsArray"
78 );
79 }
80}
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