using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; namespace NetVips; /// /// This class wraps a . /// This is used to call functions with optional arguments. See . /// public class VOption : IEnumerable> { private readonly Dictionary _internalDictionary = new(); /// /// Returns an enumerator that iterates through the . /// /// A structure for the . public IEnumerator> GetEnumerator() => _internalDictionary.GetEnumerator(); /// IEnumerator IEnumerable.GetEnumerator() => _internalDictionary.GetEnumerator(); /// /// Gets or sets the value associated with the specified key. /// /// The key of the value to get or set. /// The value associated with the specified key. public object this[string key] { get => _internalDictionary[key]; set => _internalDictionary[key] = value; } /// /// Gets a collection containing the keys in the . /// public Dictionary.KeyCollection Keys => _internalDictionary.Keys; /// /// Gets the number of key/value pairs contained in the . /// /// The number of key/value pairs contained in the . public int Count => _internalDictionary.Count; /// /// Adds the specified key and value to the . /// /// The key of the element to add. /// The value of the element to add. The value can be null for reference types. public void Add(string key, object value) => _internalDictionary.Add(key, value); /// /// Adds the specified key and value to the , if value is present. /// /// The key of the element to add. /// The value of the element to add. [MethodImpl(MethodImplOptions.AggressiveInlining)] public void AddIfPresent(string key, T? value) where T : struct { if (value.HasValue) { _internalDictionary.Add(key, value); } } /// /// Adds the specified key and class to the , if class is present. /// /// The key of the element to add. /// The value of the element to add. [MethodImpl(MethodImplOptions.AggressiveInlining)] public void AddIfPresent(string key, T cls) where T : class { if (cls != null) { _internalDictionary.Add(key, cls); } } /// /// Adds the specified key and array to the , if array is present. /// /// The key of the element to add. /// The value of the element to add. [MethodImpl(MethodImplOptions.AggressiveInlining)] public void AddIfPresent(string key, T[] array) where T : struct { if (array is { Length: > 0 }) { _internalDictionary.Add(key, array); } } /// /// Determines whether the contains the specified key. /// /// The key to locate in the . /// if the contains an element with the specified key; otherwise, . public bool ContainsKey(string key) => _internalDictionary.ContainsKey(key); /// /// Removes the value with the specified key from the . /// /// The key of the element to remove. /// if the element is successfully found and removed; otherwise, . public bool Remove(string key) => _internalDictionary.Remove(key); /// /// Gets the value associated with the specified key. /// /// The key of the value to get. /// When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized. /// if the contains an element with the specified key; otherwise, . public bool TryGetValue(string key, out object value) => _internalDictionary.TryGetValue(key, out value); }