using Invercargill.DataStructures; namespace Invercargill.Expressions { /** * Property accessor for types implementing the Lot interface. * * Provides access to Lot properties: * - `length`: The number of items in the Lot (uint) * * Example usage in expressions: * {{{ * items.length // Returns the number of items in the Lot * }}} */ public class LotPropertyAccessor : Object, PropertyAccessor { /** * The Lot value being accessed. */ private Lot? _lot; /** * Creates a new LotPropertyAccessor. * * @param lot The Lot value to access properties on */ public LotPropertyAccessor(Lot? lot) { _lot = lot; } /** * {@inheritDoc} */ public bool has_property(string property) { return property == "length"; } /** * {@inheritDoc} */ public Enumerable get_property_names() { return new Wrappers.Array(new string[]{"length"}); } /** * {@inheritDoc} */ public Element read_property(string property) throws ExpressionError { switch (property) { case "length": return new NativeElement(_lot != null ? _lot.length : 0); default: throw new ExpressionError.NON_EXISTANT_PROPERTY( @"Unknown Lot property: $property" ); } } /** * {@inheritDoc} */ public Type get_property_type(string property) throws ExpressionError { switch (property) { case "length": return typeof(uint); default: throw new ExpressionError.NON_EXISTANT_PROPERTY( @"Unknown Lot property: $property" ); } } } /** * Factory for creating LotPropertyAccessor instances. * * This factory is registered with the TypeAccessorRegistry to provide * property access for Lot values. */ public class LotPropertyAccessorFactory : Object, PropertyAccessorFactory { /** * {@inheritDoc} */ public PropertyAccessor? create(Element element) { // Check if the element's value implements Lot // We need to check for Lot since we can't check for Lot generically Lot? lot; if (element.try_get_as(out lot)) { return new LotPropertyAccessor(lot); } return null; } } }