| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using Invercargill.DataStructures;
- namespace Invercargill.Expressions {
- /**
- * Property accessor for types implementing the Lot<T> 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<Object>? _lot;
- /**
- * Creates a new LotPropertyAccessor.
- *
- * @param lot The Lot value to access properties on
- */
- public LotPropertyAccessor(Lot<Object>? lot) {
- _lot = lot;
- }
- /**
- * {@inheritDoc}
- */
- public bool has_property(string property) {
- return property == "length";
- }
- /**
- * {@inheritDoc}
- */
- public Enumerable<string> get_property_names() {
- return new Wrappers.Array<string>(new string[]{"length"});
- }
- /**
- * {@inheritDoc}
- */
- public Element read_property(string property) throws ExpressionError {
- switch (property) {
- case "length":
- return new NativeElement<uint>(_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<T> 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<Object> since we can't check for Lot<T> generically
- Lot<Object>? lot;
- if (element.try_get_as(out lot)) {
- return new LotPropertyAccessor(lot);
- }
- return null;
- }
- }
- }
|