예제 #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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        public void Enumerable_Property_Save_And_Load_Json()
        {
            EnumerableProperty p = new EnumerableProperty(100);

            p.Name     = "MyProp";
            p.Type     = typeof(decimal);
            p.Discrete = false;
            p.Start    = 5;

            var file     = GetPath();
            var property = SaveAndLoadJson(p);

            Assert.Equal(p, property);
        }
예제 #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 (_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);
        }
        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);
        }
 set => SetValue(EnumerableProperty, value);