Beispiel #1
0
        /// <summary>Generates a property.</summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="property">The property.</param>
        /// <returns>The property.</returns>
        public override Property GenerateProperty(PropertyInfo property)
        {
            if (!property.PropertyType.GetInterfaces().Contains(typeof(IEnumerable)))
            {
                throw new InvalidOperationException("Invalid Enumerable type.");
            }

            if (_length <= 0)
            {
                throw new InvalidOperationException("Cannot have an enumerable feature of 0 or less.");
            }

            Type type = property.PropertyType;
            var  ep   = new EnumerableProperty(_length);

            // good assumption??
            // TODO: Check assumptions on enums

            ep.Discrete =             //type.BaseType == typeof(Enum) ||
                          type == typeof(bool) ||
                          type == typeof(char);
            ep.Name = property.Name;

            ep.Type = type.GetElementType();
            return(ep);
        }
Beispiel #2
0
        /// <summary>Adds Enumerable property to descriptor with previousy chained name.</summary>
        /// <exception cref="DescriptorException">Thrown when a Descriptor error condition occurs.</exception>
        /// <param name="length">length of enumerable to expand.</param>
        /// <returns>descriptor with added property.</returns>
        public Descriptor AsEnumerable(int length)
        {
            if (_label)
            {
                throw new DescriptorException("Cannot use an Enumerable property as a label");
            }

            var p = new EnumerableProperty(length)
            {
                Name     = _name,
                Discrete = false
            };

            AddProperty(p);

            return(_descriptor);
        }