Class KVObject
Namespace: ValveResourceFormat.Serialization.KeyValues
Assembly: ValveResourceFormat.dll
Represents a KeyValue object data structure.
public class KVObject : IEnumerable<KeyValuePair<string, object>>, IEnumerableInheritance
Implements
IEnumerable<KeyValuePair<string, object>>, IEnumerable
Extension Methods
KVObjectExtensions.GetArray<T>(KVObject, string, Func<KVObject, T>), KVObjectExtensions.GetArray(KVObject, string), KVObjectExtensions.GetByteProperty(KVObject, string), KVObjectExtensions.GetDoubleProperty(KVObject, string), KVObjectExtensions.GetEnumValue<TEnum>(KVObject, string, bool, string), KVObjectExtensions.GetFloatArray(KVObject, string), KVObjectExtensions.GetFloatProperty(KVObject, string), KVObjectExtensions.GetInt32Property(KVObject, string), KVObjectExtensions.GetIntegerArray(KVObject, string), KVObjectExtensions.GetIntegerProperty(KVObject, string), KVObjectExtensions.GetStringProperty(KVObject, string), KVObjectExtensions.GetSubCollection(KVObject, string), KVObjectExtensions.GetUInt32Property(KVObject, string), KVObjectExtensions.GetUnsignedIntegerArray(KVObject, string), KVObjectExtensions.GetUnsignedIntegerProperty(KVObject, string), KVObjectExtensions.IsNotBlobType(KVObject, string), KVObjectExtensions.ToMatrix4x4(KVObject), KVObjectExtensions.ToQuaternion(KVObject), KVObjectExtensions.ToVector2(KVObject), KVObjectExtensions.ToVector3(KVObject), KVObjectExtensions.ToVector4(KVObject)
Constructors
KVObject(string, int)
Initializes a new instance of the 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 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 class with array items.
public KVObject(string name, IList<KVValue> arrayItems)Parameters
name string
The key name.
The array items.
KVObject(string, params (string Name, object Value)[])
Initializes a new instance of the 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
IsArray
Gets a value indicating whether this object is an array.
public bool IsArray { get; }Property Value
Key
Gets the key name of this object.
public string Key { get; }Property Value
Properties
Gets the properties dictionary.
public Dictionary<string, KVValue> Properties { get; }Property Value
this[int]
Gets the value at the specified array index.
public KVValue this[int arrayIndex] { get; }Property Value
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
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.

