BGC Tools
Static Public Member Functions
BGC.Utility.JsonUtility Class Reference

Static Public Member Functions

static JsonArray ToJsonArray< T > (this IList< T > list, Func< T, JsonValue > lambda)
 Convert list to json array with lambda that turns elements into json values More...
 
static JsonArray ToJsonArray (this IList< int > list)
 Convert list of ints to json array More...
 
static JsonArray ToJsonArray (this IList< string > list)
 Convert list of strings to json array More...
 
static T [] ToArray< T > (this JsonArray jsonArray, Func< JsonValue, T > lambda)
 Convert json array to array with lambda to convert elements to defined type More...
 
static int [] ToIntArray (this JsonArray jsonArray)
 Conver json array to array of integers More...
 
static JsonObject CombineJsonObjects (JsonObject a, JsonObject b)
 

Detailed Description

Definition at line 8 of file JsonUtility.cs.

Member Function Documentation

◆ CombineJsonObjects()

static JsonObject BGC.Utility.JsonUtility.CombineJsonObjects ( JsonObject  a,
JsonObject  b 
)
inlinestatic

Definition at line 100 of file JsonUtility.cs.

101  {
102  JsonObject combined = new JsonObject();
103 
104  foreach (KeyValuePair<string, JsonValue> json in a)
105  {
106  combined.Add(json.Key, json.Value);
107  }
108 
109  foreach (KeyValuePair<string, JsonValue> json in b)
110  {
111  Assert.IsFalse(combined.ContainsKey(json.Key));
112  combined.Add(json.Key, json.Value);
113  }
114 
115  return combined;
116  }
bool ContainsKey(string key)
Determines whether this collection contains an item assosiated with the given key.
Represents a key-value pair collection of JsonValue objects.
Definition: JsonObject.cs:13
JsonObject Add(string key)
Adds a key with a null value to this collection.

◆ ToArray< T >()

static T [] BGC.Utility.JsonUtility.ToArray< T > ( this JsonArray  jsonArray,
Func< JsonValue, T >  lambda 
)
inlinestatic

Convert json array to array with lambda to convert elements to defined type

Template Parameters
T
Parameters
jsonArray
lambda
Returns

Definition at line 71 of file JsonUtility.cs.

72  {
73  Assert.IsNotNull(lambda);
74  T[] array = new T[jsonArray.Count];
75 
76  for (int i = 0; i < array.Length; ++i)
77  {
78  array[i] = lambda(jsonArray[i]);
79  }
80 
81  return array;
82  }

◆ ToIntArray()

static int [] BGC.Utility.JsonUtility.ToIntArray ( this JsonArray  jsonArray)
inlinestatic

Conver json array to array of integers

Parameters
jsonArray
Returns

Definition at line 89 of file JsonUtility.cs.

References LightJson.JsonArray.Count.

90  {
91  int[] array = new int[jsonArray.Count];
92  for (int i = 0; i < array.Length; ++i)
93  {
94  array[i] = jsonArray[i];
95  }
96 
97  return array;
98  }

◆ ToJsonArray() [1/2]

static JsonArray BGC.Utility.JsonUtility.ToJsonArray ( this IList< int >  list)
inlinestatic

Convert list of ints to json array

Parameters
list
Returns

Definition at line 35 of file JsonUtility.cs.

References LightJson.JsonArray.Add().

36  {
37  JsonArray jsonArray = new JsonArray();
38  for (int i = 0; i < list.Count; ++i)
39  {
40  jsonArray.Add(list[i]);
41  }
42 
43  return jsonArray;
44  }
Represents an ordered collection of JsonValues.
Definition: JsonArray.cs:11
JsonArray Add(JsonValue value)
Adds the given value to this collection.
Definition: JsonArray.cs:65
Here is the call graph for this function:

◆ ToJsonArray() [2/2]

static JsonArray BGC.Utility.JsonUtility.ToJsonArray ( this IList< string >  list)
inlinestatic

Convert list of strings to json array

Parameters
list
Returns

Definition at line 51 of file JsonUtility.cs.

References LightJson.JsonArray.Add().

52  {
53  JsonArray jsonArray = new JsonArray();
54 
55  int length = list.Count;
56  for (int i = 0; i < length; ++i)
57  {
58  jsonArray.Add(list[i]);
59  }
60 
61  return jsonArray;
62  }
Represents an ordered collection of JsonValues.
Definition: JsonArray.cs:11
JsonArray Add(JsonValue value)
Adds the given value to this collection.
Definition: JsonArray.cs:65
Here is the call graph for this function:

◆ ToJsonArray< T >()

static JsonArray BGC.Utility.JsonUtility.ToJsonArray< T > ( this IList< T >  list,
Func< T, JsonValue lambda 
)
inlinestatic

Convert list to json array with lambda that turns elements into json values

Template Parameters
T
Parameters
list
lambda
Returns

Definition at line 17 of file JsonUtility.cs.

References LightJson.JsonArray.Add().

18  {
19  Assert.IsNotNull(lambda);
20 
21  JsonArray jsonArray = new JsonArray();
22  for (int i = 0; i < list.Count; ++i)
23  {
24  jsonArray.Add(lambda(list[i]));
25  }
26 
27  return jsonArray;
28  }
Represents an ordered collection of JsonValues.
Definition: JsonArray.cs:11
JsonArray Add(JsonValue value)
Adds the given value to this collection.
Definition: JsonArray.cs:65
Here is the call graph for this function:

The documentation for this class was generated from the following file: