diff --git a/ValveKeyValue/ValveKeyValue/KVCollectionValue.cs b/ValveKeyValue/ValveKeyValue/KVCollectionValue.cs index 7621c09..52d9d4c 100644 --- a/ValveKeyValue/ValveKeyValue/KVCollectionValue.cs +++ b/ValveKeyValue/ValveKeyValue/KVCollectionValue.cs @@ -1,10 +1,17 @@ using System.Collections; using System.Linq; +#nullable enable namespace ValveKeyValue { - class KVCollectionValue : KVValue, IEnumerable + /// + /// Represents a collection value. + /// + public class KVCollectionValue : KVValue, IEnumerable { + /// + /// Initializes a new instance of the class. + /// public KVCollectionValue() { children = new List(); @@ -12,28 +19,52 @@ public KVCollectionValue() readonly List children; + /// public override KVValueType ValueType => KVValueType.Collection; - public override KVValue this[string key] => Get(key)?.Value; + /// + public override KVValue? this[string key] => Get(key)?.Value; + /// + /// Adds the specified key-value object to the collection of child elements. + /// + /// The key-value object to add to the collection. Cannot be null. public void Add(KVObject value) { ArgumentNullException.ThrowIfNull(value); children.Add(value); } + /// + /// Adds the elements of the specified collection to the end of the current collection. + /// + /// The collection of instances to add. Cannot be null. public void AddRange(IEnumerable values) { ArgumentNullException.ThrowIfNull(values); children.AddRange(values); } - public KVObject Get(string name) + /// + /// Retrieves the first child element with the specified name, using the given string comparison option. + /// + /// The name of the child element to locate. Cannot be null. + /// One of the enumeration values that determines how the name comparison is performed. The default is + /// StringComparison.CurrentCulture. + /// A KVObject representing the first matching child element if found; otherwise, null. + public KVObject? Get(string name, StringComparison comparisonType = StringComparison.CurrentCulture) { ArgumentNullException.ThrowIfNull(name); - return children.FirstOrDefault(c => c.Name == name); + return children.FirstOrDefault(c => string.Equals(c.Name, name, comparisonType)); } + /// + /// Sets the value associated with the specified name, replacing any existing entry with the same name. + /// + /// If an entry with the specified name already exists, it is removed before adding the + /// new value. This method ensures that only one entry with the given name exists after the operation. + /// The name of the key to set. Cannot be null. + /// The value to associate with the specified name. Cannot be null. public void Set(string name, KVValue value) { ArgumentNullException.ThrowIfNull(name); @@ -45,90 +76,111 @@ public void Set(string name, KVValue value) #region IEnumerable + /// + /// Returns an enumerator that iterates through the collection of child KVObject instances. + /// + /// An enumerator for the collection of child KVObject objects. public IEnumerator GetEnumerator() => children.GetEnumerator(); #endregion #region IConvertible + /// public override TypeCode GetTypeCode() { throw new NotSupportedException(); } + /// public override bool ToBoolean(IFormatProvider provider) { throw new NotSupportedException(); } + /// public override byte ToByte(IFormatProvider provider) { throw new NotSupportedException(); } + /// public override char ToChar(IFormatProvider provider) { throw new NotSupportedException(); } + /// public override DateTime ToDateTime(IFormatProvider provider) { throw new NotSupportedException(); } + /// public override decimal ToDecimal(IFormatProvider provider) { throw new NotSupportedException(); } + /// public override double ToDouble(IFormatProvider provider) { throw new NotSupportedException(); } + /// public override short ToInt16(IFormatProvider provider) { throw new NotSupportedException(); } + /// public override int ToInt32(IFormatProvider provider) { throw new NotSupportedException(); } + /// public override long ToInt64(IFormatProvider provider) { throw new NotSupportedException(); } + /// public override sbyte ToSByte(IFormatProvider provider) { throw new NotSupportedException(); } + /// public override float ToSingle(IFormatProvider provider) { throw new NotSupportedException(); } + /// public override string ToString(IFormatProvider provider) => ToString(); + /// public override object ToType(Type conversionType, IFormatProvider provider) { throw new NotSupportedException(); } + /// public override ushort ToUInt16(IFormatProvider provider) { throw new NotSupportedException(); } + /// public override uint ToUInt32(IFormatProvider provider) { throw new NotSupportedException(); } + /// public override ulong ToUInt64(IFormatProvider provider) { throw new NotSupportedException(); @@ -142,6 +194,7 @@ public override ulong ToUInt64(IFormatProvider provider) #endregion + /// public override string ToString() => "[Collection]"; } }