BGC Tools
Data Structures | Public Member Functions | Static Public Member Functions | Data Fields | Static Public Attributes | Properties | Private Member Functions | Private Attributes
LightJson.JsonValue Struct Reference

A wrapper object that contains a valid JSON value. More...

Collaboration diagram for LightJson.JsonValue:
Collaboration graph
[legend]

Data Structures

class  JsonValueDebugView
 

Public Member Functions

 JsonValue (bool? value)
 Initializes a new instance of the JsonValue struct, representing a Boolean value. More...
 
 JsonValue (double? value)
 Initializes a new instance of the JsonValue struct, representing a Number value. More...
 
 JsonValue (string value)
 Initializes a new instance of the JsonValue struct, representing a String value. More...
 
 JsonValue (JsonObject value)
 Initializes a new instance of the JsonValue struct, representing a JsonObject. More...
 
 JsonValue (JsonArray value)
 Initializes a new instance of the JsonValue struct, representing a Array reference value. More...
 
override bool Equals (object obj)
 Returns a value indicating whether this JsonValue is equal to the given object. More...
 
override int GetHashCode ()
 Returns a hash code for this JsonValue. More...
 
override string ToString ()
 Returns a JSON string representing the state of the object. More...
 
string ToString (bool pretty)
 Returns a JSON string representing the state of the object. More...
 

Static Public Member Functions

static implicit operator JsonValue (bool? value)
 Converts the given nullable boolean into a JsonValue. More...
 
static implicit operator JsonValue (double? value)
 Converts the given nullable double into a JsonValue. More...
 
static implicit operator JsonValue (string value)
 Converts the given string into a JsonValue. More...
 
static implicit operator JsonValue (JsonObject value)
 Converts the given JsonObject into a JsonValue. More...
 
static implicit operator JsonValue (JsonArray value)
 Converts the given JsonArray into a JsonValue. More...
 
static implicit operator JsonValue (DateTime? value)
 Converts the given DateTime? into a JsonValue. More...
 
static implicit operator int (JsonValue jsonValue)
 Converts the given JsonValue into an Int. More...
 
static implicit operator int? (JsonValue jsonValue)
 Converts the given JsonValue into a nullable Int. More...
 
static implicit operator bool (JsonValue jsonValue)
 Converts the given JsonValue into a Bool. More...
 
static implicit operator bool? (JsonValue jsonValue)
 Converts the given JsonValue into a nullable Bool. More...
 
static implicit operator double (JsonValue jsonValue)
 Converts the given JsonValue into a Double. More...
 
static implicit operator double? (JsonValue jsonValue)
 Converts the given JsonValue into a nullable Double. More...
 
static implicit operator string (JsonValue jsonValue)
 Converts the given JsonValue into a String. More...
 
static implicit operator JsonObject (JsonValue jsonValue)
 Converts the given JsonValue into a JsonObject. More...
 
static implicit operator JsonArray (JsonValue jsonValue)
 Converts the given JsonValue into a JsonArray. More...
 
static implicit operator DateTime (JsonValue jsonValue)
 Converts the given JsonValue into a DateTime. More...
 
static implicit operator DateTime? (JsonValue jsonValue)
 Converts the given JsonValue into a nullable DateTime. More...
 
static bool operator== (JsonValue a, JsonValue b)
 Returns a value indicating whether the two given JsonValues are equal. More...
 
static bool operator!= (JsonValue a, JsonValue b)
 Returns a value indicating whether the two given JsonValues are unequal. More...
 
static JsonValue Parse (string text)
 Returns a JsonValue by parsing the given string. More...
 

Data Fields

JsonValueType Type => type
 The type of this JsonValue. More...
 
bool IsNull => Type == JsonValueType.Null
 Indicates whether this JsonValue is Null. More...
 
bool IsBoolean => Type == JsonValueType.Boolean
 Indicates whether this JsonValue is a Boolean. More...
 
bool IsNumber => Type == JsonValueType.Number
 Indicates whether this JsonValue is a Number. More...
 
bool IsString => Type == JsonValueType.String
 Indicates whether this JsonValue is a String. More...
 
bool IsJsonObject => Type == JsonValueType.Object
 Indicates whether this JsonValue is a JsonObject. More...
 
bool IsJsonArray => Type == JsonValueType.Array
 Indicates whether this JsonValue is a JsonArray. More...
 
bool IsDateTime => AsDateTime != null
 Indicates whether this JsonValue represents a DateTime. More...
 
JsonObject AsJsonObject => IsJsonObject ? (JsonObject)reference : null
 This value as an JsonObject. More...
 
JsonArray AsJsonArray => IsJsonArray ? (JsonArray)reference : null
 This value as an JsonArray. More...
 

Static Public Attributes

static readonly JsonValue Null = new JsonValue(JsonValueType.Null, default(double), null)
 Represents a null JsonValue. More...
 

Properties

bool IsInteger [get]
 Indicates whether this JsonValue is an Integer. More...
 
bool AsBoolean [get]
 This value as a Boolean type. More...
 
int AsInteger [get]
 This value as an Integer type. More...
 
double AsNumber [get]
 This value as a Number type. More...
 
string AsString [get]
 This value as a String type. More...
 
DateTime AsDateTime [get]
 This value as a System.DateTime. More...
 
object AsObject [get]
 This (inner) value as a System.object. More...
 
JsonValue this[string key] [get, set]
 The value associated with the specified key. More...
 
JsonValue this[int index] [get, set]
 The value at the specified index. More...
 

Private Member Functions

 JsonValue (JsonValueType type, double value, object reference)
 Initializes a new instance of the JsonValue struct. More...
 

Private Attributes

readonly JsonValueType type
 
readonly object reference
 
readonly double value
 

Detailed Description

A wrapper object that contains a valid JSON value.

Definition at line 13 of file JsonValue.cs.

Constructor & Destructor Documentation

◆ JsonValue() [1/6]

LightJson.JsonValue.JsonValue ( JsonValueType  type,
double  value,
object  reference 
)
inlineprivate

Initializes a new instance of the JsonValue struct.

Parameters
typeThe Json type of the JsonValue.
valueThe internal value of the JsonValue. This is used when the Json type is Number or Boolean.
referenceThe internal value reference of the JsonValue. This value is used when the Json type is String, JsonObject, or JsonArray.

Definition at line 261 of file JsonValue.cs.

References LightJson.JsonValue.reference, LightJson.JsonValue.type, and LightJson.JsonValue.value.

Referenced by LightJson.JsonValue.JsonValue().

262  {
263  this.type = type;
264  this.value = value;
265  this.reference = reference;
266  }
readonly object reference
Definition: JsonValue.cs:16
readonly JsonValueType type
Definition: JsonValue.cs:15
readonly double value
Definition: JsonValue.cs:17
Here is the caller graph for this function:

◆ JsonValue() [2/6]

LightJson.JsonValue.JsonValue ( bool?  value)
inline

Initializes a new instance of the JsonValue struct, representing a Boolean value.

Parameters
valueThe value to be wrapped.

Definition at line 272 of file JsonValue.cs.

References LightJson.JsonValue.Null.

273  {
274  if (value.HasValue)
275  {
276  type = JsonValueType.Boolean;
277  this.value = value.Value ? 1 : 0;
278  reference = null;
279  }
280  else
281  {
282  this = Null;
283  }
284  }
static readonly JsonValue Null
Represents a null JsonValue.
Definition: JsonValue.cs:20
readonly object reference
Definition: JsonValue.cs:16
JsonValueType
Enumerates the types of Json values.
Definition: JsonValueType.cs:8
readonly JsonValueType type
Definition: JsonValue.cs:15
readonly double value
Definition: JsonValue.cs:17

◆ JsonValue() [3/6]

LightJson.JsonValue.JsonValue ( double?  value)
inline

Initializes a new instance of the JsonValue struct, representing a Number value.

Parameters
valueThe value to be wrapped.

Definition at line 290 of file JsonValue.cs.

References LightJson.JsonValue.Null.

291  {
292  if (value.HasValue)
293  {
294  type = JsonValueType.Number;
295  this.value = value.Value;
296  reference = null;
297  }
298  else
299  {
300  this = Null;
301  }
302  }
static readonly JsonValue Null
Represents a null JsonValue.
Definition: JsonValue.cs:20
readonly object reference
Definition: JsonValue.cs:16
JsonValueType
Enumerates the types of Json values.
Definition: JsonValueType.cs:8
readonly JsonValueType type
Definition: JsonValue.cs:15
readonly double value
Definition: JsonValue.cs:17

◆ JsonValue() [4/6]

LightJson.JsonValue.JsonValue ( string  value)
inline

Initializes a new instance of the JsonValue struct, representing a String value.

Parameters
valueThe value to be wrapped.

Definition at line 308 of file JsonValue.cs.

References LightJson.JsonValue.Null, and LightJson.JsonValue.value.

309  {
310  if (value != null)
311  {
312  type = JsonValueType.String;
313  this.value = default(double);
314  reference = value;
315  }
316  else
317  {
318  this = Null;
319  }
320  }
static readonly JsonValue Null
Represents a null JsonValue.
Definition: JsonValue.cs:20
readonly object reference
Definition: JsonValue.cs:16
JsonValueType
Enumerates the types of Json values.
Definition: JsonValueType.cs:8
readonly JsonValueType type
Definition: JsonValue.cs:15
readonly double value
Definition: JsonValue.cs:17

◆ JsonValue() [5/6]

LightJson.JsonValue.JsonValue ( JsonObject  value)
inline

Initializes a new instance of the JsonValue struct, representing a JsonObject.

Parameters
valueThe value to be wrapped.

Definition at line 326 of file JsonValue.cs.

References LightJson.JsonValue.Null, and LightJson.JsonValue.value.

327  {
328  if (value != null)
329  {
330  type = JsonValueType.Object;
331  this.value = default(double);
332  reference = value;
333  }
334  else
335  {
336  this = Null;
337  }
338  }
static readonly JsonValue Null
Represents a null JsonValue.
Definition: JsonValue.cs:20
readonly object reference
Definition: JsonValue.cs:16
JsonValueType
Enumerates the types of Json values.
Definition: JsonValueType.cs:8
readonly JsonValueType type
Definition: JsonValue.cs:15
readonly double value
Definition: JsonValue.cs:17

◆ JsonValue() [6/6]

LightJson.JsonValue.JsonValue ( JsonArray  value)
inline

Initializes a new instance of the JsonValue struct, representing a Array reference value.

Parameters
valueThe value to be wrapped.

Definition at line 344 of file JsonValue.cs.

References LightJson.JsonValue.AsInteger, LightJson.JsonValue.IsBoolean, LightJson.JsonValue.IsInteger, LightJson.JsonValue.IsJsonArray, LightJson.JsonValue.IsJsonObject, LightJson.JsonValue.IsNull, LightJson.JsonValue.IsNumber, LightJson.JsonValue.IsString, LightJson.JsonValue.JsonValue(), LightJson.JsonValue.Null, LightJson.JsonValue.reference, and LightJson.JsonValue.value.

345  {
346  if (value != null)
347  {
348  type = JsonValueType.Array;
349  this.value = default(double);
350  reference = value;
351  }
352  else
353  {
354  this = Null;
355  }
356  }
static readonly JsonValue Null
Represents a null JsonValue.
Definition: JsonValue.cs:20
readonly object reference
Definition: JsonValue.cs:16
JsonValueType
Enumerates the types of Json values.
Definition: JsonValueType.cs:8
readonly JsonValueType type
Definition: JsonValue.cs:15
readonly double value
Definition: JsonValue.cs:17
Here is the call graph for this function:

Member Function Documentation

◆ Equals()

override bool LightJson.JsonValue.Equals ( object  obj)
inline

Returns a value indicating whether this JsonValue is equal to the given object.

Parameters
objThe object to test.

Definition at line 531 of file JsonValue.cs.

References LightJson.JsonValue.IsNull.

Referenced by LightJson.JsonValue.operator==().

532  {
533  if (obj == null)
534  {
535  //They are considered equal if both objects are null
536  return IsNull;
537  }
538 
539  JsonValue? jsonValue = obj as JsonValue?;
540 
541  if (jsonValue.HasValue)
542  {
543  //Check the actual values with the overloaded operator
544  return (this == jsonValue.Value);
545  }
546 
547  //Types don't allow for conversion to a nullable-JsonValue
548  return false;
549  }
bool IsNull
Indicates whether this JsonValue is Null.
Definition: JsonValue.cs:26
JsonValue(JsonValueType type, double value, object reference)
Initializes a new instance of the JsonValue struct.
Definition: JsonValue.cs:261
Here is the caller graph for this function:

◆ GetHashCode()

override int LightJson.JsonValue.GetHashCode ( )
inline

Returns a hash code for this JsonValue.

Definition at line 554 of file JsonValue.cs.

References LightJson.Serialization.JsonWriter.Serialize(), and LightJson.JsonValue.ToString().

555  {
556  if (IsNull)
557  {
558  return Type.GetHashCode();
559  }
560 
561  return Type.GetHashCode() ^
562  value.GetHashCode() ^
563  EqualityComparer<object>.Default.GetHashCode(reference);
564  }
readonly object reference
Definition: JsonValue.cs:16
bool IsNull
Indicates whether this JsonValue is Null.
Definition: JsonValue.cs:26
JsonValueType Type
The type of this JsonValue.
Definition: JsonValue.cs:23
readonly double value
Definition: JsonValue.cs:17
Here is the call graph for this function:

◆ operator bool()

static implicit LightJson.JsonValue.operator bool ( JsonValue  jsonValue)
static

Converts the given JsonValue into a Bool.

Parameters
jsonValueThe JsonValue to be converted.

◆ operator bool?()

static implicit LightJson.JsonValue.operator bool? ( JsonValue  jsonValue)
static

Converts the given JsonValue into a nullable Bool.

Parameters
jsonValueThe JsonValue to be converted.
Exceptions
System.InvalidCastExceptionThrows System.InvalidCastException when the inner value type of the JsonValue is not the desired type of the conversion.

◆ operator DateTime()

static implicit LightJson.JsonValue.operator DateTime ( JsonValue  jsonValue)
inlinestatic

Converts the given JsonValue into a DateTime.

Parameters
jsonValueThe JsonValue to be converted.

Definition at line 482 of file JsonValue.cs.

References LightJson.JsonValue.AsDateTime, LightJson.JsonValue.IsDateTime, and LightJson.JsonValue.IsNull.

483  {
484  DateTime? dateTime = jsonValue.AsDateTime;
485 
486  if (dateTime.HasValue)
487  {
488  return dateTime.Value;
489  }
490 
491  return DateTime.MinValue;
492  }

◆ operator DateTime?()

static implicit LightJson.JsonValue.operator DateTime? ( JsonValue  jsonValue)
static

Converts the given JsonValue into a nullable DateTime.

Parameters
jsonValueThe JsonValue to be converted.

◆ operator double()

static implicit LightJson.JsonValue.operator double ( JsonValue  jsonValue)
static

Converts the given JsonValue into a Double.

Parameters
jsonValueThe JsonValue to be converted.

◆ operator double?()

static implicit LightJson.JsonValue.operator double? ( JsonValue  jsonValue)
static

Converts the given JsonValue into a nullable Double.

Parameters
jsonValueThe JsonValue to be converted.
Exceptions
System.InvalidCastExceptionThrows System.InvalidCastException when the inner value type of the JsonValue is not the desired type of the conversion.

◆ operator int()

static implicit LightJson.JsonValue.operator int ( JsonValue  jsonValue)
static

Converts the given JsonValue into an Int.

Parameters
jsonValueThe JsonValue to be converted.

◆ operator int?()

static implicit LightJson.JsonValue.operator int? ( JsonValue  jsonValue)
static

Converts the given JsonValue into a nullable Int.

Parameters
jsonValueThe JsonValue to be converted.
Exceptions
System.InvalidCastExceptionThrows System.InvalidCastException when the inner value type of the JsonValue is not the desired type of the conversion.

◆ operator JsonArray()

static implicit LightJson.JsonValue.operator JsonArray ( JsonValue  jsonValue)
static

Converts the given JsonValue into a JsonArray.

Parameters
jsonValueThe JsonValue to be converted.

◆ operator JsonObject()

static implicit LightJson.JsonValue.operator JsonObject ( JsonValue  jsonValue)
static

Converts the given JsonValue into a JsonObject.

Parameters
jsonValueThe JsonValue to be converted.

◆ operator JsonValue() [1/6]

static implicit LightJson.JsonValue.operator JsonValue ( bool?  value)
static

Converts the given nullable boolean into a JsonValue.

Parameters
valueThe value to be converted.

◆ operator JsonValue() [2/6]

static implicit LightJson.JsonValue.operator JsonValue ( double?  value)
static

Converts the given nullable double into a JsonValue.

Parameters
valueThe value to be converted.

◆ operator JsonValue() [3/6]

static implicit LightJson.JsonValue.operator JsonValue ( string  value)
static

Converts the given string into a JsonValue.

Parameters
valueThe value to be converted.

◆ operator JsonValue() [4/6]

static implicit LightJson.JsonValue.operator JsonValue ( JsonObject  value)
static

Converts the given JsonObject into a JsonValue.

Parameters
valueThe value to be converted.

◆ operator JsonValue() [5/6]

static implicit LightJson.JsonValue.operator JsonValue ( JsonArray  value)
static

Converts the given JsonArray into a JsonValue.

Parameters
valueThe value to be converted.

◆ operator JsonValue() [6/6]

static implicit LightJson.JsonValue.operator JsonValue ( DateTime?  value)
static

Converts the given DateTime? into a JsonValue.

The DateTime value will be stored as a string using ISO 8601 format, since JSON does not define a DateTime type.

Parameters
valueThe value to be converted.

◆ operator string()

static implicit LightJson.JsonValue.operator string ( JsonValue  jsonValue)
static

Converts the given JsonValue into a String.

Parameters
jsonValueThe JsonValue to be converted.

◆ operator!=()

static bool LightJson.JsonValue.operator!= ( JsonValue  a,
JsonValue  b 
)
static

Returns a value indicating whether the two given JsonValues are unequal.

Parameters
aA JsonValue to compare.
bA JsonValue to compare.

Referenced by LightJson.JsonValue.operator==().

Here is the caller graph for this function:

◆ operator==()

static bool LightJson.JsonValue.operator== ( JsonValue  a,
JsonValue  b 
)
inlinestatic

Returns a value indicating whether the two given JsonValues are equal.

Parameters
aA JsonValue to compare.
bA JsonValue to compare.

Definition at line 507 of file JsonValue.cs.

References LightJson.JsonValue.Equals(), LightJson.JsonValue.operator!=(), LightJson.Serialization.JsonReader.Parse(), LightJson.JsonValue.Parse(), LightJson.JsonValue.reference, LightJson.JsonValue.Type, and LightJson.JsonValue.value.

508  {
509  return a.Type == b.Type &&
510  a.value == b.value &&
511  Equals(a.reference, b.reference);
512  }
override bool Equals(object obj)
Returns a value indicating whether this JsonValue is equal to the given object.
Definition: JsonValue.cs:531
Here is the call graph for this function:

◆ Parse()

static JsonValue LightJson.JsonValue.Parse ( string  text)
static

Returns a JsonValue by parsing the given string.

Parameters
textThe JSON-formatted string to be parsed.

Referenced by LightJson.JsonValue.operator==().

Here is the caller graph for this function:

◆ ToString() [1/2]

override string LightJson.JsonValue.ToString ( )

Returns a JSON string representing the state of the object.

The resulting string is safe to be inserted as is into dynamically generated JavaScript or JSON code.

Referenced by LightJson.JsonValue.GetHashCode().

Here is the caller graph for this function:

◆ ToString() [2/2]

string LightJson.JsonValue.ToString ( bool  pretty)

Returns a JSON string representing the state of the object.

The resulting string is safe to be inserted as is into dynamically generated JavaScript or JSON code.

Parameters
prettyIndicates whether the resulting string should be formatted for human-readability.

Field Documentation

◆ AsJsonArray

JsonArray LightJson.JsonValue.AsJsonArray => IsJsonArray ? (JsonArray)reference : null

This value as an JsonArray.

Definition at line 155 of file JsonValue.cs.

Referenced by BGC.IO.ResourceInfo.InitializeResourceInfo().

◆ AsJsonObject

JsonObject LightJson.JsonValue.AsJsonObject => IsJsonObject ? (JsonObject)reference : null

This value as an JsonObject.

Definition at line 152 of file JsonValue.cs.

◆ IsBoolean

bool LightJson.JsonValue.IsBoolean => Type == JsonValueType.Boolean

Indicates whether this JsonValue is a Boolean.

Definition at line 29 of file JsonValue.cs.

Referenced by BGC.Study.ProtocolManager.GetEnvBool(), and LightJson.JsonValue.JsonValue().

◆ IsDateTime

bool LightJson.JsonValue.IsDateTime => AsDateTime != null

Indicates whether this JsonValue represents a DateTime.

Definition at line 61 of file JsonValue.cs.

Referenced by LightJson.JsonValue.operator DateTime().

◆ IsJsonArray

bool LightJson.JsonValue.IsJsonArray => Type == JsonValueType.Array

Indicates whether this JsonValue is a JsonArray.

Definition at line 58 of file JsonValue.cs.

Referenced by LightJson.JsonValue.JsonValue().

◆ IsJsonObject

bool LightJson.JsonValue.IsJsonObject => Type == JsonValueType.Object

Indicates whether this JsonValue is a JsonObject.

Definition at line 55 of file JsonValue.cs.

Referenced by LightJson.JsonValue.JsonValue().

◆ IsNull

bool LightJson.JsonValue.IsNull => Type == JsonValueType.Null

◆ IsNumber

bool LightJson.JsonValue.IsNumber => Type == JsonValueType.Number

Indicates whether this JsonValue is a Number.

Definition at line 49 of file JsonValue.cs.

Referenced by BGC.Study.ProtocolManager.GetEnvFloat(), and LightJson.JsonValue.JsonValue().

◆ IsString

bool LightJson.JsonValue.IsString => Type == JsonValueType.String

Indicates whether this JsonValue is a String.

Definition at line 52 of file JsonValue.cs.

Referenced by BGC.Study.ProtocolManager.GetEnvStr(), and LightJson.JsonValue.JsonValue().

◆ Null

readonly JsonValue LightJson.JsonValue.Null = new JsonValue(JsonValueType.Null, default(double), null)
static

◆ reference

readonly object LightJson.JsonValue.reference
private

Definition at line 16 of file JsonValue.cs.

Referenced by LightJson.JsonValue.JsonValue(), and LightJson.JsonValue.operator==().

◆ type

readonly JsonValueType LightJson.JsonValue.type
private

Definition at line 15 of file JsonValue.cs.

Referenced by LightJson.JsonValue.JsonValue().

◆ Type

JsonValueType LightJson.JsonValue.Type => type

◆ value

readonly double LightJson.JsonValue.value
private

Definition at line 17 of file JsonValue.cs.

Referenced by LightJson.JsonValue.JsonValue(), and LightJson.JsonValue.operator==().

Property Documentation

◆ AsBoolean

bool LightJson.JsonValue.AsBoolean
get

This value as a Boolean type.

Definition at line 65 of file JsonValue.cs.

Referenced by BGC.Study.ProtocolManager.GetEnvBool().

◆ AsDateTime

DateTime LightJson.JsonValue.AsDateTime
get

This value as a System.DateTime.

Definition at line 159 of file JsonValue.cs.

Referenced by LightJson.JsonValue.operator DateTime().

◆ AsInteger

int LightJson.JsonValue.AsInteger
get

◆ AsNumber

double LightJson.JsonValue.AsNumber
get

This value as a Number type.

Definition at line 104 of file JsonValue.cs.

Referenced by BGC.Study.ProtocolManager.GetEnvFloat().

◆ AsObject

object LightJson.JsonValue.AsObject
get

This (inner) value as a System.object.

Definition at line 175 of file JsonValue.cs.

◆ AsString

string LightJson.JsonValue.AsString
get

This value as a String type.

Definition at line 131 of file JsonValue.cs.

Referenced by BGC.Study.ProtocolManager.GetEnvStr(), and LightJson.Serialization.JsonWriter.WriteEncodedJsonValue().

◆ IsInteger

bool LightJson.JsonValue.IsInteger
get

◆ this[int index]

JsonValue LightJson.JsonValue.this[int index]
getset

The value at the specified index.

Parameters
indexThe zero-based index of the value to get or set.
Exceptions
InvalidOperationExceptionThrown when this JsonValue is not a JsonArray

Definition at line 228 of file JsonValue.cs.

◆ this[string key]

JsonValue LightJson.JsonValue.this[string key]
getset

The value associated with the specified key.

Parameters
keyThe key of the value to get or set.
Exceptions
InvalidOperationExceptionThrown when this JsonValue is not a JsonObject.

Definition at line 201 of file JsonValue.cs.


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