6using Newtonsoft.Json.Linq;
35 List<BadObject> a = array.Where(x => x !=
null).Select(
ConvertNode).ToList();
47 Dictionary<string, BadObject> t =
new Dictionary<string, BadObject>();
49 foreach (KeyValuePair<string, JToken?> keyValuePair
in obj)
67 return JValue.CreateNull();
79 _ =>
throw new Exception(
"Unsupported value type: " + value.GetType()),
91 JObject obj =
new JObject();
93 foreach (KeyValuePair<string, BadObject> keyValuePair
in table.InnerTable)
95 obj.Add(keyValuePair.Key,
ConvertNode(keyValuePair.Value));
108 JArray array =
new JArray();
110 foreach (
BadObject node
in value.InnerArray)
128 case JTokenType.Integer:
129 if (value.Value is
int i)
134 return (decimal)(long)value.Value!;
135 case JTokenType.Float:
136 return value.Value
switch
138 float f => (decimal)f,
140 _ => (decimal)(double)value.Value!,
143 case JTokenType.String:
144 return (
string)value.Value!;
145 case JTokenType.Boolean:
146 return (
bool)value.Value!;
147 case JTokenType.Guid:
148 return value.Value!.ToString();
149 case JTokenType.Date:
150 return value.Value<DateTime>().ToString(
"O");
151 case JTokenType.Null:
153 case JTokenType.None:
154 case JTokenType.Object:
155 case JTokenType.Array:
156 case JTokenType.Constructor:
157 case JTokenType.Property:
158 case JTokenType.Comment:
159 case JTokenType.Undefined:
161 case JTokenType.Bytes:
163 case JTokenType.TimeSpan:
165 throw new Exception(
"Unsupported Json type: " + value.Type);
183 _ =>
throw new Exception(
"Unsupported node type: " + node.GetType()),
194 JToken o = JToken.Parse(s);
208 return token.ToString();
Exposes the BadScript Runtime Functionality to Consumers.
BadRuntime UseApi(BadInteropApi api, bool replace=false)
Adds or Replaces a specified API.
Implements the "Json" Api.
Implements a Json to BadObject Converter.
static JToken ConvertNode(BadObject value)
Converts a BadObject to a JToken.
static BadObject FromJson(string s)
Converts a Json string to a BadObject.
static string ToJson(BadObject o)
Converts a BadObject to a Json string.
static BadRuntime UseJsonApi(this BadRuntime runtime)
Configures the Runtime to use the Json API.
static BadArray ConvertArray(JArray array)
Converts a JArray to a BadArray.
static BadObject ConvertValue(JValue value)
Converts a JValue to a BadObject.
static JObject ConvertTable(BadTable table)
Converts a BadTable to a JObject.
static BadTable ConvertObject(JObject obj)
Converts a JObject to a BadTable.
static BadObject ConvertNode(JToken? node)
Converts a JToken to a BadObject.
static JArray ConvertArray(BadArray value)
Converts a BadArray to a JArray.
Implements a Reflected Object.
object Instance
The Instance of the Reflected Object.
Implements a Dynamic List/Array for the BadScript Language.
The Base Class for all BadScript Objects.
static readonly BadObject Null
The Null Value for the BadScript Language.
Implements a Table Structure for the BadScript Language.
Implements a function that can be called from the script.
override string ToSafeString(List< BadObject > done)
Implements the Interface for Native Boolean.
new bool Value
The Boolean Value.
Implements the Interface for Native Numbers.
new decimal Value
The Number Value.
Implements the Interface for Native Strings.
new string Value
The String Value.
Contains JSON Extensions and APIs for the BadScript2 Runtime.
Contains the Classes for Reflection Objects.
Contains Runtime Function Objects.
Contains the Native Runtime Objects.
Contains the Runtime Objects.