Class DynaObject
A row read without a type to map to, its columns reachable by name or index. Ask for a DynaObject
when the shape is not known ahead of time, it reads like a dictionary of the result's columns and
serializes to JSON as one. Values keep their column types, read them with Get<T>(string).
[JsonConverter(typeof(DynaObjectConverter))]
public abstract class DynaObject : IReadOnlyDictionary<string, object?>, IReadOnlyCollection<KeyValuePair<string, object?>>, IEnumerable<KeyValuePair<string, object?>>, IReadOnlyDictionary<string, int>, IReadOnlyCollection<KeyValuePair<string, int>>, IEnumerable<KeyValuePair<string, int>>, IEnumerable
- Inheritance
-
DynaObject
- Implements
- Inherited Members
- Extension Methods
Fields
Mapper
Gets the column names and their indexes.
public readonly Mapper Mapper
Field Value
Properties
Count
Gets the number of elements in the collection.
public int Count { get; }
Property Value
- int
The number of elements in the collection.
this[int]
public object? this[int ind] { get; set; }
Parameters
indint
Property Value
this[ReadOnlySpan<char>]
public object? this[ReadOnlySpan<char> key] { get; set; }
Parameters
keyReadOnlySpan<char>
Property Value
this[string]
Gets the element that has the specified key in the read-only dictionary.
public object? this[string key] { get; set; }
Parameters
keystringThe key to locate.
Property Value
- object
The element that has the specified key in the read-only dictionary.
Exceptions
- ArgumentNullException
keyis null.- KeyNotFoundException
The property is retrieved and
keyis not found.
Keys
Gets the unique keys held by this mapper as a ReadOnlySpan<T>.
public ReadOnlySpan<string> Keys { get; }
Property Value
Values
Gets an enumerable collection that contains the values in the read-only dictionary.
public IEnumerable<object?> Values { get; }
Property Value
- IEnumerable<object>
An enumerable collection that contains the values in the read-only dictionary.
Methods
ContainsKey(ReadOnlySpan<char>)
public bool ContainsKey(ReadOnlySpan<char> key)
Parameters
keyReadOnlySpan<char>
Returns
ContainsKey(string)
Determines whether the read-only dictionary contains an element that has the specified key.
public bool ContainsKey(string key)
Parameters
keystringThe key to locate.
Returns
- bool
true if the read-only dictionary contains an element that has the specified key; otherwise, false.
Exceptions
- ArgumentNullException
keyis null.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<KeyValuePair<string, object?>> GetEnumerator()
Returns
- IEnumerator<KeyValuePair<string, object>>
An enumerator that can be used to iterate through the collection.
Get<T>(int)
Gets the value at the given column index.
public T Get<T>(int index)
Parameters
indexint
Returns
- T
Type Parameters
T
Get<T>(ReadOnlySpan<char>)
Gets the value from the named column.
public T Get<T>(ReadOnlySpan<char> key)
Parameters
keyReadOnlySpan<char>
Returns
- T
Type Parameters
T
Get<T>(string)
Gets the value from the named column.
public T Get<T>(string key)
Parameters
keystring
Returns
- T
Type Parameters
T
Set<T>(int, T)
Tries to replace the value at the given column index.
public abstract bool Set<T>(int index, T value)
Parameters
indexintvalueT
Returns
Type Parameters
T
Set<T>(ReadOnlySpan<char>, T)
Tries to replace the value in the named column.
public bool Set<T>(ReadOnlySpan<char> key, T value)
Parameters
keyReadOnlySpan<char>valueT
Returns
Type Parameters
T
Set<T>(string, T)
Tries to replace the value in the named column.
public bool Set<T>(string key, T value)
Parameters
keystringvalueT
Returns
Type Parameters
T
TryGetValue(ReadOnlySpan<char>, out object?)
public bool TryGetValue(ReadOnlySpan<char> key, out object? value)
Parameters
keyReadOnlySpan<char>valueobject
Returns
TryGetValue(string, out int)
Gets the value that is associated with the specified key.
public bool TryGetValue(string key, out int value)
Parameters
keystringThe key to locate.
valueintWhen this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the
valueparameter. This parameter is passed uninitialized.
Returns
- bool
true if the object that implements the IReadOnlyDictionary<TKey, TValue> interface contains an element that has the specified key; otherwise, false.
Exceptions
- ArgumentNullException
keyis null.
TryGetValue(string, out object?)
Gets the value that is associated with the specified key.
public bool TryGetValue(string key, out object? value)
Parameters
keystringThe key to locate.
valueobjectWhen this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the
valueparameter. This parameter is passed uninitialized.
Returns
- bool
true if the object that implements the IReadOnlyDictionary<TKey, TValue> interface contains an element that has the specified key; otherwise, false.
Exceptions
- ArgumentNullException
keyis null.
TryGetValue<T>(ReadOnlySpan<char>, out T)
public bool TryGetValue<T>(ReadOnlySpan<char> key, out T value)
Parameters
keyReadOnlySpan<char>valueT
Returns
Type Parameters
T
TryGetValue<T>(string, out T)
public bool TryGetValue<T>(string key, out T value)
Parameters
keystringvalueT
Returns
Type Parameters
T
TryGet<T>(int, out T)
Tries to read the value at the given column index.
public abstract bool TryGet<T>(int index, out T val)
Parameters
indexintvalT
Returns
Type Parameters
T
TrySet<T, TField>(T, ref TField?)
Stores value into field when its type matches, used while filling a typed slot.
protected static bool TrySet<T, TField>(T value, ref TField? field)
Parameters
valueTfieldTField
Returns
Type Parameters
TTField
WriteJsonProperties(Utf8JsonWriter, JsonSerializerOptions)
Writes the columns as JSON properties, used by the JSON converter.
public abstract void WriteJsonProperties(Utf8JsonWriter writer, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriteroptionsJsonSerializerOptions