A game about forced loneliness, made by TACStudios
1using System.Collections;
2
3namespace Unity.VisualScripting
4{
5 /// <summary>
6 /// Checks whether a dictionary contains the specified key.
7 /// </summary>
8 [UnitCategory("Collections/Dictionaries")]
9 [UnitSurtitle("Dictionary")]
10 [UnitShortTitle("Contains Key")]
11 [TypeIcon(typeof(IDictionary))]
12 public sealed class DictionaryContainsKey : Unit
13 {
14 /// <summary>
15 /// The dictionary.
16 /// </summary>
17 [DoNotSerialize]
18 [PortLabelHidden]
19 public ValueInput dictionary { get; private set; }
20
21 /// <summary>
22 /// The key.
23 /// </summary>
24 [DoNotSerialize]
25 [PortLabelHidden]
26 public ValueInput key { get; private set; }
27
28 /// <summary>
29 /// Whether the list contains the item.
30 /// </summary>
31 [DoNotSerialize]
32 [PortLabelHidden]
33 public ValueOutput contains { get; private set; }
34
35 protected override void Definition()
36 {
37 dictionary = ValueInput<IDictionary>(nameof(dictionary));
38 key = ValueInput<object>(nameof(key));
39 contains = ValueOutput(nameof(contains), Contains);
40
41 Requirement(dictionary, contains);
42 Requirement(key, contains);
43 }
44
45 private bool Contains(Flow flow)
46 {
47 var dictionary = flow.GetValue<IDictionary>(this.dictionary);
48 var key = flow.GetValue<object>(this.key);
49
50 return dictionary.Contains(key);
51 }
52 }
53}