using System.Collections; namespace Unity.VisualScripting { /// /// Checks whether a dictionary contains the specified key. /// [UnitCategory("Collections/Dictionaries")] [UnitSurtitle("Dictionary")] [UnitShortTitle("Contains Key")] [TypeIcon(typeof(IDictionary))] public sealed class DictionaryContainsKey : Unit { /// /// The dictionary. /// [DoNotSerialize] [PortLabelHidden] public ValueInput dictionary { get; private set; } /// /// The key. /// [DoNotSerialize] [PortLabelHidden] public ValueInput key { get; private set; } /// /// Whether the list contains the item. /// [DoNotSerialize] [PortLabelHidden] public ValueOutput contains { get; private set; } protected override void Definition() { dictionary = ValueInput(nameof(dictionary)); key = ValueInput(nameof(key)); contains = ValueOutput(nameof(contains), Contains); Requirement(dictionary, contains); Requirement(key, contains); } private bool Contains(Flow flow) { var dictionary = flow.GetValue(this.dictionary); var key = flow.GetValue(this.key); return dictionary.Contains(key); } } }