using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; namespace TriInspector.Resolvers { public class DropdownValuesResolver { [CanBeNull] private ValueResolver>> _itemsResolver; [CanBeNull] private ValueResolver> _valuesResolver; [PublicAPI] public static DropdownValuesResolver Resolve(TriPropertyDefinition propertyDefinition, string expression) { var valuesResolver = ValueResolver.Resolve>(propertyDefinition, expression); if (!valuesResolver.TryGetErrorString(out _)) { return new DropdownValuesResolver { _valuesResolver = valuesResolver, }; } var itemsResolver = ValueResolver.Resolve>>(propertyDefinition, expression); return new DropdownValuesResolver { _itemsResolver = itemsResolver, }; } [PublicAPI] public bool TryGetErrorString(out string error) { return ValueResolver.TryGetErrorString(_valuesResolver, _itemsResolver, out error); } [PublicAPI] public IEnumerable GetDropdownItems(TriProperty property) { if (_valuesResolver != null) { var values = _valuesResolver.GetValue(property, Enumerable.Empty()); foreach (var value in values) { yield return new TriDropdownItem {Text = $"{value}", Value = value,}; } } if (_itemsResolver != null) { var values = _itemsResolver.GetValue(property, Enumerable.Empty>()); foreach (var value in values) { yield return value; } } } } }