public FlexibleArguments()
 {
     // Default descriptor for the only real property
     var reflPropDesc = TypeDescriptor.GetProperties(this, noCustomTypeDesc: true).Find("PropCount", false);
     myProps.Add(reflPropDesc);
     // Add some fake properties to start with
     // This one has a unit:
     myProps.Add(new MyPropertyDescriptor("SomeIntParam", typeof(int), "s"));
     var resProp = new MyPropertyDescriptor("SomeCalculationResult", typeof(int));
     resProp.AddAttribute(new ReadOnlyAttribute(true));
     myProps.Add(resProp);
     myProps.Add(new MyPropertyDescriptor("SomeStringParam", typeof(string)));
     myProps.Add(new MyPropertyDescriptor("SomeBoolParam", typeof(bool)));
     PropCount = (uint)myProps.Count;
 }
		/// <summary>
		/// Creates new or sets existing property of this instance.
		/// </summary>
		/// <param name="Name">Name of the property.</param>
		/// <param name="Value">Value of the property.</param>
		/// <param name="ReadOnly">Determines whether the property is read-only.</param>
		/// <param name="Description">Description of the property or <c>null</c> if no description is needed.</param>
		/// <param name="Category">Category of the property or <c>null</c> if no category is needed.</param>
		public void SetProperty( string Name, string Value, bool ReadOnly, string Description, string Category )
		{
			// Set attributes of this property
			ArrayList attributes = new ArrayList();
			attributes.Add( new ReadOnlyAttribute(ReadOnly) );
			if( Description!= null )
				attributes.Add( new DescriptionAttribute(Description) );
			if( Category!=null )
				attributes.Add( new CategoryAttribute(Category) );				

			MyPropertyDescriptor desc = new MyPropertyDescriptor( this, Name, Value, ReadOnly, (Attribute[])attributes.ToArray(typeof(Attribute)) );

			_properties[Name] = desc;
		}
		PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
		{
			MyPropertyDescriptor[] ret = new MyPropertyDescriptor[ _properties.Count ];

			int i=0;
			foreach( MyPropertyDescriptor desc in _properties.Values )
				ret[i++] = desc;		

			return( new PropertyDescriptorCollection(ret) );
		}
Esempio n. 4
0
        public void TestGetPropertyDescriptorKey()
        {
            // First use AttributePropertyDescriptor and MultiPropertyDescriptor
            {
                // Make sure that different property descriptor objects with the same Name, Category and Type
                //  have the same hash code, using PropertyUtils.GetPropertyDescriptorHash().
                var attrPropertyDescriptor = new AttributePropertyDescriptor(
                    "TestName", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "TestCategory", "Test description", false);
                var multiPropertyDescriptor = new MultiPropertyDescriptor(attrPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(attrPropertyDescriptor, multiPropertyDescriptor));

                // Make sure that null Category names work, too.
                attrPropertyDescriptor = new AttributePropertyDescriptor(
                    "TestName", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    null, "Test description", false);
                multiPropertyDescriptor = new MultiPropertyDescriptor(attrPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(attrPropertyDescriptor, multiPropertyDescriptor));

                // Make sure that if the Name and Category and identical, that it works with other property
                //  descriptors who also have identical Name and Category strings. This makes sure that we
                //  are not using 'xor' between the Name and Category.
                attrPropertyDescriptor = new AttributePropertyDescriptor(
                    "SameName", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "SameName", "Name and Category are the same!", false);
                multiPropertyDescriptor = new MultiPropertyDescriptor(attrPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(attrPropertyDescriptor, multiPropertyDescriptor));

                var d2 = new AttributePropertyDescriptor(
                    "AnotherSameName", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "AnotherSameName", "Name and Category are the same!", false);
                var m2 = new MultiPropertyDescriptor(d2);
                Assert.IsTrue(IsSameHashKey(d2, m2));

                Assert.IsTrue(!IsSameHashKey(attrPropertyDescriptor, d2));

                // Make sure that if the Name and Category are swapped, that they yield different codes.
                attrPropertyDescriptor = new AttributePropertyDescriptor(
                    "Name1", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "Name2", "Test description", false);
                d2 = new AttributePropertyDescriptor(
                    "Name2", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "Name1", "Test description", false);
                Assert.IsTrue(!IsSameHashKey(attrPropertyDescriptor, d2));
            }

            // Now use a stub property descriptor and MultiPropertyDescriptor
            {
                // Make sure that different property descriptor objects with the same Name, Category and Type
                //  have the same hash code, using PropertyUtils.GetPropertyDescriptorHash().
                var stubPropertyDescriptor = new MyPropertyDescriptor("TestName", "TestCategory", typeof(string));
                var multiPropertyDescriptor = new MultiPropertyDescriptor(stubPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(stubPropertyDescriptor, multiPropertyDescriptor));

                // Make sure that null Category names work, too.
                stubPropertyDescriptor = new MyPropertyDescriptor("TestName", null, typeof(string));
                multiPropertyDescriptor = new MultiPropertyDescriptor(stubPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(stubPropertyDescriptor, multiPropertyDescriptor));

                // Make sure that if the Name and Category and identical, that it works with other property
                //  descriptors who also have identical Name and Category strings. This makes sure that we
                //  are not using 'xor' between the Name and Category.
                stubPropertyDescriptor = new MyPropertyDescriptor("SameName", "SameName", typeof(string));
                multiPropertyDescriptor = new MultiPropertyDescriptor(stubPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(stubPropertyDescriptor, multiPropertyDescriptor));

                var d2 = new MyPropertyDescriptor("AnotherSameName", "AnotherSameName", typeof(string));
                var m2 = new MultiPropertyDescriptor(d2);
                Assert.IsTrue(IsSameHashKey(d2, m2));

                Assert.IsTrue(!IsSameHashKey(stubPropertyDescriptor, d2));

                // Make sure that if the Name and Category are swapped, that they yield different codes.
                stubPropertyDescriptor = new MyPropertyDescriptor("Name1", "Name2", typeof(string));
                d2 = new MyPropertyDescriptor("Name2", "Name1", typeof(string));
                Assert.IsTrue(!IsSameHashKey(stubPropertyDescriptor, d2));
            }
        }
Esempio n. 5
0
        public void TestGetPropertyDescriptorKey()
        {
            // First use AttributePropertyDescriptor and MultiPropertyDescriptor
            {
                // Make sure that different property descriptor objects with the same Name, Category and Type
                //  have the same hash code, using PropertyUtils.GetPropertyDescriptorHash().
                var attrPropertyDescriptor = new AttributePropertyDescriptor(
                    "TestName", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "TestCategory", "Test description", false);
                var multiPropertyDescriptor = new MultiPropertyDescriptor(attrPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(attrPropertyDescriptor, multiPropertyDescriptor));

                // Make sure that null Category names work, too.
                attrPropertyDescriptor = new AttributePropertyDescriptor(
                    "TestName", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    null, "Test description", false);
                multiPropertyDescriptor = new MultiPropertyDescriptor(attrPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(attrPropertyDescriptor, multiPropertyDescriptor));

                // Make sure that if the Name and Category and identical, that it works with other property
                //  descriptors who also have identical Name and Category strings. This makes sure that we
                //  are not using 'xor' between the Name and Category.
                attrPropertyDescriptor = new AttributePropertyDescriptor(
                    "SameName", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "SameName", "Name and Category are the same!", false);
                multiPropertyDescriptor = new MultiPropertyDescriptor(attrPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(attrPropertyDescriptor, multiPropertyDescriptor));

                var d2 = new AttributePropertyDescriptor(
                    "AnotherSameName", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "AnotherSameName", "Name and Category are the same!", false);
                var m2 = new MultiPropertyDescriptor(d2);
                Assert.IsTrue(IsSameHashKey(d2, m2));

                Assert.IsTrue(!IsSameHashKey(attrPropertyDescriptor, d2));

                // Make sure that if the Name and Category are swapped, that they yield different codes.
                attrPropertyDescriptor = new AttributePropertyDescriptor(
                    "Name1", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "Name2", "Test description", false);
                d2 = new AttributePropertyDescriptor(
                    "Name2", new AttributeInfo("TestAttrName", new AttributeType("TestAttrName", typeof(string))),
                    "Name1", "Test description", false);
                Assert.IsTrue(!IsSameHashKey(attrPropertyDescriptor, d2));
            }

            // Now use a stub property descriptor and MultiPropertyDescriptor
            {
                // Make sure that different property descriptor objects with the same Name, Category and Type
                //  have the same hash code, using PropertyUtils.GetPropertyDescriptorHash().
                var stubPropertyDescriptor  = new MyPropertyDescriptor("TestName", "TestCategory", typeof(string));
                var multiPropertyDescriptor = new MultiPropertyDescriptor(stubPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(stubPropertyDescriptor, multiPropertyDescriptor));

                // Make sure that null Category names work, too.
                stubPropertyDescriptor  = new MyPropertyDescriptor("TestName", null, typeof(string));
                multiPropertyDescriptor = new MultiPropertyDescriptor(stubPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(stubPropertyDescriptor, multiPropertyDescriptor));

                // Make sure that if the Name and Category and identical, that it works with other property
                //  descriptors who also have identical Name and Category strings. This makes sure that we
                //  are not using 'xor' between the Name and Category.
                stubPropertyDescriptor  = new MyPropertyDescriptor("SameName", "SameName", typeof(string));
                multiPropertyDescriptor = new MultiPropertyDescriptor(stubPropertyDescriptor);
                Assert.IsTrue(IsSameHashKey(stubPropertyDescriptor, multiPropertyDescriptor));

                var d2 = new MyPropertyDescriptor("AnotherSameName", "AnotherSameName", typeof(string));
                var m2 = new MultiPropertyDescriptor(d2);
                Assert.IsTrue(IsSameHashKey(d2, m2));

                Assert.IsTrue(!IsSameHashKey(stubPropertyDescriptor, d2));

                // Make sure that if the Name and Category are swapped, that they yield different codes.
                stubPropertyDescriptor = new MyPropertyDescriptor("Name1", "Name2", typeof(string));
                d2 = new MyPropertyDescriptor("Name2", "Name1", typeof(string));
                Assert.IsTrue(!IsSameHashKey(stubPropertyDescriptor, d2));
            }
        }