Table of Contents

Class KVObject

Namespace
ValveResourceFormat.Serialization.KeyValues
Assembly
ValveResourceFormat.dll

Represents a KeyValue object data structure.

public class KVObject : IEnumerable<KeyValuePair<string, object>>, IEnumerable

Inheritance

Implements

Inherited Members

Extension Methods

Constructors

KVObject(string, int)

Initializes a new instance of the ValveResourceFormat.Serialization.KeyValues.KVObject class.

public KVObject(string name, int capacity = 0)

Parameters

name string

The key name.

capacity int

The initial capacity.

KVObject(string, bool, int)

Initializes a new instance of the ValveResourceFormat.Serialization.KeyValues.KVObject class.

public KVObject(string name, bool isArray, int capacity = 0)

Parameters

name string

The key name.

isArray bool

Whether this object is an array.

capacity int

The initial capacity.

KVObject(string, IList<KVValue>)

Initializes a new instance of the ValveResourceFormat.Serialization.KeyValues.KVObject class with array items.

public KVObject(string name, IList<KVValue> arrayItems)

Parameters

name string

The key name.

arrayItems IList<KVValue>

The array items.

KVObject(string, params (string Name, object Value)[])

Initializes a new instance of the ValveResourceFormat.Serialization.KeyValues.KVObject class with properties.

public KVObject(string name, params (string Name, object Value)[] properties)

Parameters

name string

The key name.

properties (string Name, object Value)[]

The properties to add.

Properties

Count

Gets the number of properties or items in this object.

public int Count { get; }

Property Value

int

IsArray

Gets a value indicating whether this object is an array.

public bool IsArray { get; }

Property Value

bool

Key

Gets the key name of this object.

public string Key { get; }

Property Value

string

Properties

Gets the properties dictionary.

public Dictionary<string, KVValue> Properties { get; }

Property Value

Dictionary<string, KVValue>

this[int]

Gets the value at the specified array index.

public KVValue this[int arrayIndex] { get; }

Property Value

KVValue

Methods

AddProperty(string, KVValue)

Adds a property to the structure.

public virtual void AddProperty(string name, KVValue value)

Parameters

name string

The property name.

value KVValue

The property value.

AddProperty(string, object)

Adds a property to the structure.

public void AddProperty(string name, object value)

Parameters

name string

The property name.

value object

The property value.

ContainsKey(string)

Determines whether this object contains the specified key.

public bool ContainsKey(string name)

Parameters

name string

The key name.

Returns

bool

True if the key exists; otherwise, false.

GetArray<T>(string)

Gets an array property by name.

public T[] GetArray<T>(string name)

Parameters

name string

The property name.

Returns

T[]

The array, or default if the property doesn't exist.

Type Parameters

T

The element type of the array.

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.

GetProperty<T>(string, T)

Gets a property value by name with type conversion.

public T GetProperty<T>(string name, T defaultValue = default)

Parameters

name string

The property name.

defaultValue T

The default value if the property doesn't exist.

Returns

T

The property value or default value.

Type Parameters

T

The type to convert to.

GetPropertyUnchecked<T>(string, T)

Gets a property value by name with unchecked type conversion, attempting to parse strings as numbers.

public T GetPropertyUnchecked<T>(string name, T defaultValue = default)

Parameters

name string

The property name.

defaultValue T

The default value if the property doesn't exist.

Returns

T

The property value or default value.

Type Parameters

T

The type to convert to.

Serialize(IndentedTextWriter)

Serializes this object to the specified writer.

public void Serialize(IndentedTextWriter writer)

Parameters

writer IndentedTextWriter

The writer to serialize to.