Class KVObjectExtensions
Namespace: ValveResourceFormat.Serialization.KeyValues
Assembly: ValveResourceFormat.dll
VRF-specific extension methods for KVObject. These provide the same behavior as the old VRF KVObject property getters.
public static class KVObjectExtensionsInheritance
object ← KVObjectExtensions
Methods
DeserializeWithoutRoot(KVSerializer, Stream)
Deserializes KeyValues1 text that keeps several keys at its top level rather than a single root.
public static KVObject DeserializeWithoutRoot(this KVSerializer serializer, Stream stream)Parameters
serializer KVSerializer
A KeyValues1 text serializer.
stream Stream
The text to read.
Returns
KVObject
An object holding every top level key.
GetArray(KVObject, string)
Gets the values of an array child by name. Returns the underlying collection without copying.
public static IReadOnlyList<KVObject> GetArray(this KVObject obj, string name)Parameters
obj KVObject
name string
Returns
IReadOnlyList<KVObject>
GetArray<T>(KVObject, string)
Gets a typed array of primitive values by name. Also handles binary blobs.
public static T[] GetArray<T>(this KVObject obj, string name)Parameters
obj KVObject
name string
Returns
T[]
Type Parameters
T
GetBooleanProperty(KVObject, string, bool)
Gets a boolean property from the key-value object.
public static bool GetBooleanProperty(this KVObject obj, string name, bool defaultValue = false)Parameters
obj KVObject
name string
defaultValue bool
Returns
bool
GetByteProperty(KVObject, string, byte)
Gets a byte property from the key-value object.
public static byte GetByteProperty(this KVObject obj, string name, byte defaultValue = 0)Parameters
obj KVObject
name string
defaultValue byte
Returns
byte
GetDoubleProperty(KVObject, string, double)
Gets a double property from the key-value object.
public static double GetDoubleProperty(this KVObject obj, string name, double defaultValue = 0)Parameters
obj KVObject
name string
defaultValue double
Returns
double
GetEnumValue<TEnum>(KVObject, string, bool, string)
Gets an enum value from the key-value object.
public static TEnum GetEnumValue<TEnum>(this KVObject obj, string name, bool normalize = false, string stripExtension = "Flags") where TEnum : struct, EnumParameters
obj KVObject
name string
normalize bool
stripExtension string
Returns
TEnum
Type Parameters
TEnum
GetFloatArray(KVObject, string)
Gets an array of floats by name.
public static float[] GetFloatArray(this KVObject obj, string name)Parameters
obj KVObject
name string
Returns
float[]
GetFloatProperty(KVObject, string, float)
Gets a float property from the key-value object.
public static float GetFloatProperty(this KVObject obj, string name, float defaultValue = 0)Parameters
obj KVObject
name string
defaultValue float
Returns
float
GetInt32Property(KVObject, string, int)
Gets an Int32 property from the key-value object.
public static int GetInt32Property(this KVObject obj, string name, int defaultValue = 0)Parameters
obj KVObject
name string
defaultValue int
Returns
int
GetIntegerArray(KVObject, string)
Gets an array of long integers by name.
public static long[] GetIntegerArray(this KVObject obj, string name)Parameters
obj KVObject
name string
Returns
long[]
GetIntegerProperty(KVObject, string, long)
Gets a 64-bit integer property from the key-value object.
public static long GetIntegerProperty(this KVObject obj, string name, long defaultValue = 0)Parameters
obj KVObject
name string
defaultValue long
Returns
long
GetStringProperty(KVObject, string, string?)
Gets a string property from the key-value object.
public static string GetStringProperty(this KVObject obj, string name, string? defaultValue = null)Parameters
obj KVObject
name string
defaultValue string?
Returns
string
GetSubCollection(KVObject, string)
Gets a child KVObject (sub-collection) by name.
public static KVObject GetSubCollection(this KVObject obj, string name)Parameters
obj KVObject
name string
Returns
KVObject
GetUInt32Property(KVObject, string, uint)
Gets a UInt32 property from the key-value object.
public static uint GetUInt32Property(this KVObject obj, string name, uint defaultValue = 0)Parameters
obj KVObject
name string
defaultValue uint
Returns
uint
GetUnsignedIntegerArray(KVObject, string)
Gets an unsigned integer array of 64-bit bit patterns, with unchecked int-to-ulong conversion for binary KV3 compatibility.
public static ulong[] GetUnsignedIntegerArray(this KVObject obj, string name)Parameters
obj KVObject
name string
Returns
ulong[]
GetUnsignedIntegerArray<T>(KVObject, string)
Gets an unsigned integer array whose elements are bit patterns, such as flags, masks or hashes. Elements are truncated to T instead of range checked, so negative values keep their bits.
public static T[] GetUnsignedIntegerArray<T>(this KVObject obj, string name) where T : unmanaged, IBinaryInteger<T>, IUnsignedNumber<T>Parameters
obj KVObject
name string
Returns
T[]
Type Parameters
T
GetUnsignedIntegerProperty(KVObject, string, ulong)
Gets an unsigned integer property, with unchecked int-to-ulong conversion for binary KV3 compatibility.
public static ulong GetUnsignedIntegerProperty(this KVObject obj, string name, ulong defaultValue = 0)Parameters
obj KVObject
name string
defaultValue ulong
Returns
ulong
IsNotBlobType(KVObject, string)
Determines whether the specified key contains an array (not a blob type).
public static bool IsNotBlobType(this KVObject obj, string key)Parameters
obj KVObject
key string
Returns
bool
NormalizeEnumName<TEnum>(string, string)
Normalize C Style VALVE_ENUM_SOME_VALUE to C# ValveEnum.SomeValue (underscores and digits are stripped)
public static string NormalizeEnumName<TEnum>(string name, string stripExtension = "") where TEnum : EnumParameters
name string
stripExtension string
Returns
string
Type Parameters
TEnum
ToMatrix4x4(IReadOnlyList<KVObject>)
Converts an array of key-value objects to a Matrix4x4.
public static Matrix4x4 ToMatrix4x4(this IReadOnlyList<KVObject> array)Parameters
array IReadOnlyList<KVObject>
Returns
ToMatrix4x4(KVObject)
Converts the key-value object to a Matrix4x4.
public static Matrix4x4 ToMatrix4x4(this KVObject array)Parameters
array KVObject
Returns
ToQuaternion(KVObject)
Converts the key-value object to a Quaternion.
public static Quaternion ToQuaternion(this KVObject obj)Parameters
obj KVObject
Returns
ToTransform(KVObject)
Converts the key-value object to a tuple containing Position, Uniform Scale, and Rotation.
public static (Vector3 Position, float Scale, Quaternion Rotation) ToTransform(this KVObject obj)Parameters
obj KVObject
Returns
(Vector3 Position, float Scale, Quaternion Rotation)
ToVector2(KVObject)
Converts the key-value object to a Vector2.
public static Vector2 ToVector2(this KVObject obj)Parameters
obj KVObject
Returns
ToVector3(KVObject)
Converts the key-value object to a Vector3.
public static Vector3 ToVector3(this KVObject obj)Parameters
obj KVObject
Returns
ToVector4(KVObject)
Converts the key-value object to a Vector4.
public static Vector4 ToVector4(this KVObject obj)Parameters
obj KVObject

