/// <include file='doc\DataGridGeneralPage.uex' path='docs/doc[@for="DataGridGeneralPage.LoadDataSourceFields"]/*' /> /// <devdoc> /// </devdoc> private void LoadDataSourceFields() { EnterLoadingMode(); dataKeyFieldCombo.SelectedIndex = -1; dataKeyFieldCombo.Items.Clear(); dataKeyFieldCombo.EnsureNotSetItem(); if (currentDataSource != null) { PropertyDescriptorCollection fields = currentDataSource.Fields; if (fields != null) { IEnumerator fieldEnum = fields.GetEnumerator(); while (fieldEnum.MoveNext()) { PropertyDescriptor fieldDesc = (PropertyDescriptor)fieldEnum.Current; if (BaseDataList.IsBindableType(fieldDesc.PropertyType)) { dataKeyFieldCombo.AddItem(fieldDesc.Name); } } } } ExitLoadingMode(); }
/// <summary> /// </summary> private void LoadDataSourceFields() { using (new LoadingModeResource(this)) { _dataTextFieldCombo.SelectedIndex = -1; _dataTextFieldCombo.Items.Clear(); _dataTextFieldCombo.EnsureNotSetItem(); _dataValueFieldCombo.SelectedIndex = -1; _dataValueFieldCombo.Items.Clear(); _dataValueFieldCombo.EnsureNotSetItem(); if (_currentDataSource != null) { PropertyDescriptorCollection fields = _currentDataSource.Fields; if (fields != null) { IEnumerator fieldEnum = fields.GetEnumerator(); while (fieldEnum.MoveNext()) { PropertyDescriptor fieldDesc = (PropertyDescriptor)fieldEnum.Current; if (BaseDataList.IsBindableType(fieldDesc.PropertyType)) { _dataTextFieldCombo.AddItem(fieldDesc.Name); _dataValueFieldCombo.AddItem(fieldDesc.Name); } } } } } }
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { List <CustomPropertyDescriptor> tmpPDCLst = new List <CustomPropertyDescriptor>(); PropertyDescriptorCollection tmpPDC = TypeDescriptor.GetProperties(mCurrentSelectObject, attributes); IEnumerator tmpIe = tmpPDC.GetEnumerator(); CustomPropertyDescriptor tmpCPD; PropertyDescriptor tmpPD; while (tmpIe.MoveNext()) { tmpPD = tmpIe.Current as PropertyDescriptor; if (mObjectAttribs.ContainsKey(tmpPD.Name)) { tmpCPD = new CustomPropertyDescriptor(mCurrentSelectObject, tmpPD); tmpCPD.SetDisplayName(mObjectAttribs[tmpPD.Name]); if (mObjectGroup.ContainsKey(tmpPD.Name)) { tmpCPD.SetCategory(mObjectGroup[tmpPD.Name]); } else { tmpCPD.SetCategory(tmpPD.Category + "中文"); } tmpPDCLst.Add(tmpCPD); } } return(new PropertyDescriptorCollection(tmpPDCLst.ToArray())); }
public static IEnumerable <PropertyDescriptor> GetProperties(object source) // this object source) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(source); var numer = properties.GetEnumerator(); while (numer.MoveNext()) { // https://raw.githubusercontent.com/Microsoft/referencesource/master/System/compmod/system/componentmodel/ReflectPropertyDescriptor.cs // ReflectPropertyDescriptor yield return(numer.Current as PropertyDescriptor); } }
// <Snippet1> private void MyEnumerator() { // Creates a new collection and assigns it the properties for button1. PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1); // Creates an enumerator. IEnumerator ie = properties.GetEnumerator(); // Prints the name of each property in the collection. Object myProperty; while (ie.MoveNext() == true) { myProperty = ie.Current; textBox1.Text += myProperty.ToString() + '\n'; } }
/// <summary> /// </summary> private void LoadDataSourceFields() { using (new LoadingModeResource(this)) { ObjectList objectList = (ObjectList)GetBaseControl(); _cmbLabelField.SelectedIndex = -1; _cmbLabelField.Items.Clear(); _cmbLabelField.EnsureNotSetItem(); _xLists.Clear(); if (_currentDataSource == null) { return; } // Use StringCollection to preserve the order, note the items // are case-sensitivie StringCollection availableFieldCollection = new StringCollection(); // Get available fields from custom defined fields foreach (ObjectListField customDefinedField in objectList.Fields) { _cmbLabelField.AddItem(customDefinedField.Name); availableFieldCollection.Add(customDefinedField.Name); } // Get available fields from DataSource if (objectList.AutoGenerateFields) { PropertyDescriptorCollection fields = _currentDataSource.Fields; if (fields != null) { IEnumerator fieldEnum = fields.GetEnumerator(); while (fieldEnum.MoveNext()) { PropertyDescriptor fieldDesc = (PropertyDescriptor)fieldEnum.Current; if (IsBindableType(fieldDesc.PropertyType)) { _cmbLabelField.AddItem(fieldDesc.Name); availableFieldCollection.Add(fieldDesc.Name); } } } } // Match selected fields from TableFields Debug.Assert(objectList.TableFields != null); if (objectList.TableFields != String.Empty && !_dataSourceDirty) { Char[] separator = new Char[] { ';' }; String[] tableFields = objectList.TableFields.Split(separator); foreach (String selectedField in tableFields) { for (int i = 0; i < availableFieldCollection.Count; i++) { String availableField = availableFieldCollection[i]; if (String.Compare(selectedField, availableField, true, CultureInfo.InvariantCulture) == 0) { _xLists.AddToSelectedList(availableField); availableFieldCollection.RemoveAt(i); break; } } } } // Add the remaining unselected available fields back to AvailableList foreach (String availableField in availableFieldCollection) { _xLists.AddToAvailableList(availableField); } _xLists.Initialize(); } }