Click or drag to resize

LdValue Structure

An immutable instance of any data type that is allowed in JSON.

Namespace:  LaunchDarkly.Client
Assembly:  LaunchDarkly.CommonSdk (in LaunchDarkly.CommonSdk.dll) Version: 2.11.0
Syntax
public struct LdValue : IEquatable<LdValue>

The LdValue type exposes the following members.

Properties
  NameDescription
Public propertyAsBool
Gets the boolean value if this is a boolean.
Public propertyAsDouble
Gets the value as an double if it is numeric.
Public propertyAsFloat
Gets the value as an float if it is numeric.
Public propertyAsInt
Gets the value as an int if it is numeric.
Public propertyAsLong
Gets the value as an long if it is numeric.
Public propertyAsString
Gets the string value if this is a string.
Public propertyCount
The number of values if this is an array or object; otherwise zero.
Public propertyIsInt
True if the wrapped value is an integer.
Public propertyIsNull
True if the wrapped value is .
Public propertyIsNumber
True if the wrapped value is numeric.
Public propertyIsString
True if the wrapped value is a string.
Public propertyStatic memberNull
Convenience property for an LdValue that wraps a value.
Public propertyType
The type of the JSON value.
Top
Methods
  NameDescription
Public methodStatic memberCode exampleArrayFrom
Initializes an LdValue as an array, from a sequence of JSON values.
Public methodStatic memberCode exampleArrayOf
Initializes an LdValue as an array, from a sequence of JSON values.
Public methodAsDictionaryT
Converts the value to a read-only dictionary.
Public methodAsJToken Obsolete.
Converts the value to a JToken.
Public methodAsListT
Converts the value to a read-only list of elements of some type.
Public methodStatic memberBuildArray
Starts building an array value.
Public methodStatic memberBuildObject
Starts building an object value.
Public methodEquals(Object)
Performs a deep-equality comparison using DeepEquals(JToken).
(Overrides ValueTypeEquals(Object).)
Public methodEquals(LdValue)
Performs a deep-equality comparison using DeepEquals(JToken).
Public methodStatic memberFromJToken Obsolete.
Initializes an LdValue from a JToken.
Public methodGet(Int32)
Retrieves an array item or object key by index. Never throws an exception.
Public methodGet(String)
Retrieves a object value by key. Never throws an exception.
Public methodGetHashCode
Returns the hash code for this instance.
(Overrides ValueTypeGetHashCode.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStatic memberObjectFrom
Initializes an LdValue as a JSON object, from a dictionary.
Public methodStatic memberOf(Boolean)
Initializes an LdValue from a boolean value.
Public methodStatic memberOf(Double)
Initializes an LdValue from a double value.
Public methodStatic memberOf(Int32)
Initializes an LdValue from an int value.
Public methodStatic memberOf(Int64)
Initializes an LdValue from a long value.
Public methodStatic memberOf(Single)
Initializes an LdValue from a float value.
Public methodStatic memberOf(String)
Initializes an LdValue from a string value.
Public methodStatic memberParse
Parses a value from its JSON encoding.
Public methodToJsonString
Converts the value to its JSON encoding.
Public methodToString (Overrides ValueTypeToString.)
Top
Remarks

This is used as the return type of the client's JsonVariation method, and also as the type of custom attributes in User and IUserBuilder.

While the LaunchDarkly SDK uses Newtonsoft.Json types to represent JSON values, some of those types (object and array) are mutable. In contexts where it is important for data to remain immutable after it is created, these values are represented with LdValue instead. It is easily convertible to primitive types and array/dictionary structures.

Note that this is a struct, not a class, so it is always passed by value and is not nullable; JSON nulls are represented by the constant Null and can be detected with IsNull. Whenever possible, LdValue stores primitive types within the struct rather than allocating an object on the heap.

There are several ways to create an LdValue. For primitive types, use the various overloads of "Of" such as Of(Boolean); these are very efficient since they do not allocate any objects on the heap. For arrays and objects (dictionaries), use ArrayFrom(IEnumerableLdValue), ArrayOf(LdValue), ObjectFrom(IReadOnlyDictionaryString, LdValue), or the corresponding methods in the type-specific LdValueConvert instances.

To convert to other types, there are the "As" properties such as use the various overloads of "Of" such as Of(Boolean); these are very efficient since they do not allocate any objects on the heap. For arrays and objects (dictionaries), use AsListT(LdValueConverterT) or AsDictionaryT(LdValueConverterT).

Currently, there is also the option of converting to or from the Newtonsoft.Json type JToken. However, those methods may be removed in the future in order to avoid this third-party API dependency.

See Also