Enumerable property. Expanded feature.
Inheritance: Property
Example #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);
        }
        public void Enumerable_Property_Save_And_Load()
        {
            EnumerableProperty p = new EnumerableProperty(100);
            p.Name = "MyProp";
            p.Type = typeof(decimal);
            p.Discrete = false;
            p.Start = 5;

            Serialize(p);
            var property = Deserialize<EnumerableProperty>();
            Assert.Equal(p, property);
        }
Example #3
0
        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.");

            var ep = new EnumerableProperty(_length);
            // unless proven otherwise
            // at expansion time
            ep.Discrete = false;
            ep.Name = property.Name;
            return ep;
        }
Example #4
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 (this._label)
            {
                throw new DescriptorException("Cannot use an Enumerable property as a label");
            }

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

            this.AddProperty(p);

            return(this._descriptor);
        }
        public void Enumerable_Property_Save_And_Load()
        {
            EnumerableProperty p = new EnumerableProperty(100);
            p.Name = "MyProp";
            p.Type = typeof(decimal);
            p.Discrete = false;
            p.Start = 5;

            Serialize(p);

            var po = Deserialize<EnumerableProperty>();

            Assert.AreEqual(p.Name, po.Name);
            Assert.AreEqual(p.Type, po.Type);
            Assert.AreEqual(p.Discrete, po.Discrete);
            Assert.AreEqual(p.Start, po.Start);
            Assert.AreEqual(p.Length, po.Length);
        }
Example #6
0
        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??
            ep.Discrete = type.BaseType == typeof(Enum) ||
                          type == typeof(bool) ||
                          type == typeof(char);
            ep.Name = property.Name;

            ep.Type = type.GetElementType();
            return ep;
        }
Example #7
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;
        }