6using Newtonsoft.Json.Linq;
35 List<BadObject> a = array.Where(x => x !=
null)
49 Dictionary<string, BadObject> t =
new Dictionary<string, BadObject>();
51 foreach (KeyValuePair<string, JToken?> keyValuePair
in obj)
69 return JValue.CreateNull();
81 _ =>
throw new Exception(
"Unsupported value type: " + value.GetType()),
93 JObject obj =
new JObject();
95 foreach (KeyValuePair<string, BadObject> keyValuePair
in table.InnerTable)
97 obj.Add(keyValuePair.Key,
ConvertNode(keyValuePair.Value));
110 JArray array =
new JArray();
112 foreach (
BadObject node
in value.InnerArray)
130 case JTokenType.Integer:
131 if (value.Value is
int i)
135 if(value.Value is
byte b)
139 if(value.Value is sbyte sb)
143 if(value.Value is
short s)
147 if(value.Value is ushort us)
151 if(value.Value is uint ui)
155 if(value.Value is
long l)
159 if(value.Value is ulong ul)
164 return (
long)value.Value!;
165 case JTokenType.Float:
166 return value.Value
switch
168 float f => (decimal)f,
170 _ => (decimal)(double)value.Value!,
173 case JTokenType.String:
174 return (
string)value.Value!;
175 case JTokenType.Boolean:
176 return (
bool)value.Value!;
177 case JTokenType.Guid:
179 case JTokenType.Date:
180 return value.Value<DateTime>()
182 case JTokenType.Null:
184 case JTokenType.None:
185 case JTokenType.Object:
186 case JTokenType.Array:
187 case JTokenType.Constructor:
188 case JTokenType.Property:
189 case JTokenType.Comment:
190 case JTokenType.Undefined:
192 case JTokenType.Bytes:
194 case JTokenType.TimeSpan:
196 throw new Exception(
"Unsupported Json type: " + value.Type);
214 _ =>
throw new Exception(
"Unsupported node type: " + node.GetType()),
225 JToken o = JToken.Parse(s);
239 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.
override string ToString()
Returns a String Representation of this Object.
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.