using System.Collections;
namespace Unity.VisualScripting
{
///
/// Clears all items from a dictionary.
///
[UnitCategory("Collections/Dictionaries")]
[UnitSurtitle("Dictionary")]
[UnitShortTitle("Clear")]
[UnitOrder(4)]
[TypeIcon(typeof(RemoveDictionaryItem))]
public sealed class ClearDictionary : Unit
{
///
/// The entry point for the node.
///
[DoNotSerialize]
[PortLabelHidden]
public ControlInput enter { get; private set; }
///
/// The dictionary.
///
[DoNotSerialize]
[PortLabel("Dictionary")]
[PortLabelHidden]
public ValueInput dictionaryInput { get; private set; }
///
/// The cleared dictionary.
/// Note that the input dictionary is modified directly and then returned.
///
[DoNotSerialize]
[PortLabel("Dictionary")]
[PortLabelHidden]
public ValueOutput dictionaryOutput { get; private set; }
///
/// The action to execute once the dictionary has been cleared.
///
[DoNotSerialize]
[PortLabelHidden]
public ControlOutput exit { get; private set; }
protected override void Definition()
{
enter = ControlInput(nameof(enter), Clear);
dictionaryInput = ValueInput(nameof(dictionaryInput));
dictionaryOutput = ValueOutput(nameof(dictionaryOutput));
exit = ControlOutput(nameof(exit));
Requirement(dictionaryInput, enter);
Assignment(enter, dictionaryOutput);
Succession(enter, exit);
}
private ControlOutput Clear(Flow flow)
{
var dictionary = flow.GetValue(dictionaryInput);
flow.SetValue(dictionaryOutput, dictionary);
dictionary.Clear();
return exit;
}
}
}