예제 #1
0
        public void GetProperties_SomePropertiesWithOrderAttribute_ReturnElementsInDesiredOrdering()
        {
            // Setup
            var dynamicPropertyBag = new DynamicPropertyBag(new TestOrderedProperties());

            // Call
            PropertyDescriptorCollection propertyDescriptorCollection = dynamicPropertyBag.GetProperties();

            // Assert
            var index = 0;

            Assert.AreEqual("PropSix", propertyDescriptorCollection[index++].DisplayName);
            Assert.AreEqual("PropFour", propertyDescriptorCollection[index++].DisplayName);
            Assert.AreEqual("PropTwo", propertyDescriptorCollection[index++].DisplayName);
            Assert.AreEqual("PropOne", propertyDescriptorCollection[index++].DisplayName);
            Assert.AreEqual("Description", propertyDescriptorCollection[index++].DisplayName);
            Assert.AreEqual("PropFive", propertyDescriptorCollection[index++].DisplayName);
            Assert.AreEqual("Name", propertyDescriptorCollection[index++].DisplayName);

            PropertyDescriptor propThreeDescriptor = propertyDescriptorCollection.Find("PropThree", false);

            Assert.GreaterOrEqual(propertyDescriptorCollection.IndexOf(propThreeDescriptor), index,
                                  "PropThree is not decorated with PropertyOrderAttribute or DynamicPropertyOrderAttribute, therefore should come after those that are.");
            PropertyDescriptor propSevenDescriptor = propertyDescriptorCollection.Find("PropSeven", false);

            Assert.GreaterOrEqual(propertyDescriptorCollection.IndexOf(propSevenDescriptor), index,
                                  "PropSeven is not decorated with PropertyOrderAttribute or DynamicPropertyOrderAttribute, therefore should come after those that are.");
        }
        public void can_create()
        {
            var property0 = PropertyDescriptor.For(typeof(DecoratedType).GetProperty("Property0"));
            var property1 = PropertyDescriptor.For(typeof(DecoratedType).GetProperty("Property1"));
            var collection = new PropertyDescriptorCollection(new[] { property0, property1 });

            Assert.True(collection.Contains(property0));
            Assert.True(collection.Contains(property1));
            Assert.Equal(2, collection.Count);
            Assert.Equal(0, collection.IndexOf(property0));
            Assert.Equal(1, collection.IndexOf(property1));
        }
예제 #3
0
        protected override object ImportFromObject(ImportContext context, JsonReader reader)
        {
            Debug.Assert(context != null);
            Debug.Assert(reader != null);

            reader.Read();

            object obj = Activator.CreateInstance(OutputType);
            INonObjectMemberImporter otherImporter = obj as INonObjectMemberImporter;

            while (reader.TokenClass != JsonTokenClass.EndObject)
            {
                string memberName = reader.ReadMember();

                PropertyDescriptor property = _properties.Find(memberName, true);

                //
                // Skip over the member value and continue with reading if
                // the property was not found or if the property found cannot
                // be set.
                //

                if (property == null || property.IsReadOnly)
                {
                    if (otherImporter == null || !otherImporter.Import(context, memberName, reader))
                    {
                        reader.Skip();
                    }
                    continue;
                }

                //
                // Check if the property defines a custom import scheme.
                // If yes, ask it to import the value into the property
                // and then continue with the next.
                //

                if (_importers != null)
                {
                    int index = _properties.IndexOf(property);

                    IObjectMemberImporter importer = _importers[index];

                    if (importer != null)
                    {
                        importer.Import(context, reader, obj);
                        continue;
                    }
                }

                //
                // Import from reader based on the property type and
                // then set the value of the property.
                //

                property.SetValue(obj, context.Import(property.PropertyType, reader));
            }

            return(ReadReturning(reader, obj));
        }
예제 #4
0
        private void FilterProperties(string filter)
        {
            _FilteredPropertyDescriptors.Clear();
            List <string> props = new List <string>(); // = filter.Split(';');

            props.AddRange(filter.Split(';'));

            foreach (string p in props)
            {
                PropertyDescriptor descriptor = _FullPropertyDescriptors.Find(p, true);
                if (descriptor != null)
                {
                    _FilteredPropertyDescriptors.Add(descriptor);
                }
                else
                {
                    descriptor = _FullPropertyDescriptors.Find(p.ArrayName(), true);
                    if (descriptor != null)
                    {
                        if (_FilteredPropertyDescriptors.IndexOf(descriptor) < 0)
                        {
                            _FilteredPropertyDescriptors.Add(descriptor);
                        }
                    }
                }
            }
        }
예제 #5
0
 public IEnumerable <string> Names(int iFrom = 1)
 {
     foreach (PropertyDescriptor item in list)
     {
         if (list.IndexOf(item) >= iFrom)
         {
             yield return(item.Name);
         }
     }
 }
        private void OnSourceListPropertyDescriptorAdded(ListChangedEventArgs e)
        {
            _pdc = ListUtil.GetItemProperties(SourceList);
            int field       = _pdc.IndexOf(e.PropertyDescriptor);
            int columnIndex = field + 1;

            Model.InsertColumns(columnIndex, 1);
            BlinkQueueInsertField(field, null);
            //InsertDirtyCellColumns(columnIndex, 1, null);
            InsertTotalField(field, 1);
            InvalidateVisual(true);
        }
        private void OnSourceListPropertyDescriptorDeleted(ListChangedEventArgs e)
        {
            int field = _pdc.IndexOf(e.PropertyDescriptor);

            _pdc = ListUtil.GetItemProperties(SourceList);
            int columnIndex = field + 1;

            Model.RemoveColumns(columnIndex, 1);
            BlinkQueueDeleteField(field, null);
            //RemoveDirtyCellColumns(columnIndex, 1, null);
            RemoveTotalField(field, 1);
            InvalidateVisual(true);
        }
        private void OnSourceListPropertyDescriptorChanged(ListChangedEventArgs e)
        {
            _pdc = ListUtil.GetItemProperties(SourceList);
            int field       = _pdc.IndexOf(e.PropertyDescriptor);
            int columnIndex = field + 1;

            InvalidateCell(GridRangeInfo.Col(columnIndex));
            InvalidateCell(new RowColumnIndex(SourceList.Count + 1, columnIndex));
            if (IsColumnVisible(columnIndex))
            {
                InvalidateVisual(false);
            }
        }
예제 #9
0
        /// <summary>
        /// 查找属性位置
        /// </summary>
        /// <param name="propName"></param>
        /// <returns></returns>
        protected int IndexOf(String propName)
        {
            if (values == null)
            {
                return(-1);
            }
            if (values.Length == 1)
            {
                return(0);
            }
            PropertyDescriptorCollection pds = this.GetPropertyDescriptorCollection();

            return(pds.IndexOf(propName));
        }
        public int GetOrdinal(string fieldName)
        {
            int result = -1;

            if (fieldName != null && m_columns != null && m_columns.Count > 0)
            {
                PropertyDescriptor propertyDescriptor = m_columns[fieldName];
                if (propertyDescriptor != null)
                {
                    result = m_columns.IndexOf(propertyDescriptor);
                }
            }
            return(result);
        }
        protected override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            PropertyDescriptorCollection descriptors          = base.GetProperties(attributes);
            PropertyDescriptor           dataSourceDescriptor = descriptors.Find("DataSource", true);

            if (dataSourceDescriptor != null)
            {
                int index = descriptors.IndexOf(dataSourceDescriptor);
                PropertyDescriptor[] descriptorArray = new PropertyDescriptor[descriptors.Count];
                descriptors.CopyTo(descriptorArray, 0);
                descriptorArray[index] = new DynamicPropertyDescriptor(dataSourceDescriptor, new TypeConverterAttribute(typeof(DataSourceConverter)));
                (descriptorArray[index] as DynamicPropertyDescriptor).CanResetValueHandler = new CanResetValueHandler(CanResetDataSource);
                (descriptorArray[index] as DynamicPropertyDescriptor).ResetValueHandler    = new ResetValueHandler(ResetDataSource);
                descriptors = new PropertyDescriptorCollection(descriptorArray, true);
            }
            return(descriptors);
        }
        protected override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            PropertyDescriptorCollection descriptors = base.GetProperties(attributes);

            if (_disableProviderSelection)
            {
                PropertyDescriptor providerDescriptor = descriptors.Find("Provider", true);
                if (providerDescriptor != null)
                {
                    int index = descriptors.IndexOf(providerDescriptor);
                    PropertyDescriptor[] descriptorArray = new PropertyDescriptor[descriptors.Count];
                    descriptors.CopyTo(descriptorArray, 0);
                    descriptorArray[index] = new DynamicPropertyDescriptor(providerDescriptor, ReadOnlyAttribute.Yes);
                    (descriptorArray[index] as DynamicPropertyDescriptor).CanResetValueHandler = new CanResetValueHandler(CanResetProvider);
                    descriptors = new PropertyDescriptorCollection(descriptorArray, true);
                }
            }
            return(descriptors);
        }
예제 #13
0
 public object GetItemAt(int rowIndex, string columnName)
 {
     if (DataSource == null)
     {
         throw new InvalidOperationException("DataSource Must be set to call GetItemAt()");
     }
     else
     {
         PropertyDescriptorCollection pdc = DataManager.GetItemProperties();
         PropertyDescriptor           pd  = pdc.Find(columnName, true);
         if (pd == null)
         {
             throw new ArgumentException("'" + columnName + "' not found in the column collection", "columnName");
         }
         else
         {
             return(GetItemAt(rowIndex, pdc.IndexOf(pd)));
         }
     }
 }
        protected override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            PropertyDescriptorCollection descriptors = base.GetProperties(attributes);

            if (Access12ProviderRegistered)
            {
                DynamicPropertyDescriptor providerDescriptor = descriptors.Find("Provider", true) as DynamicPropertyDescriptor;
                if (providerDescriptor != null)
                {
                    if (!DisableProviderSelection)
                    {
                        providerDescriptor.SetIsReadOnly(false);
                    }
                    providerDescriptor.SetConverterType(typeof(JetProviderConverter));
                    providerDescriptor.AddValueChanged(ConnectionStringBuilder, new EventHandler(OnProviderChanged));
                }
                PropertyDescriptor dataSourceDescriptor = descriptors.Find("DataSource", true);
                if (dataSourceDescriptor != null)
                {
                    int index = descriptors.IndexOf(dataSourceDescriptor);
                    PropertyDescriptor[] descriptorArray = new PropertyDescriptor[descriptors.Count];
                    descriptors.CopyTo(descriptorArray, 0);
                    descriptorArray[index] = new DynamicPropertyDescriptor(dataSourceDescriptor);
                    descriptorArray[index].AddValueChanged(ConnectionStringBuilder, new EventHandler(OnDataSourceChanged));
                    descriptors = new PropertyDescriptorCollection(descriptorArray, true);
                }
            }
            PropertyDescriptor passwordDescriptor = descriptors.Find("Jet OLEDB:Database Password", true);

            if (passwordDescriptor != null)
            {
                int index = descriptors.IndexOf(passwordDescriptor);
                PropertyDescriptor[] descriptorArray = new PropertyDescriptor[descriptors.Count];
                descriptors.CopyTo(descriptorArray, 0);
                descriptorArray[index] = new DynamicPropertyDescriptor(passwordDescriptor, PasswordPropertyTextAttribute.Yes);
                descriptors            = new PropertyDescriptorCollection(descriptorArray, true);
            }
            return(descriptors);
        }