Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / RelatedPropertyManager.cs / 1305376 / RelatedPropertyManager.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using System; using Microsoft.Win32; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.ComponentModel; using System.Collections; internal class RelatedPropertyManager : PropertyManager { BindingManagerBase parentManager; string dataField; PropertyDescriptor fieldInfo; [ SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors") // If the constructor does not set the dataSource // it would be a breaking change. ] internal RelatedPropertyManager(BindingManagerBase parentManager, string dataField) : base(GetCurrentOrNull(parentManager), dataField) { Bind(parentManager, dataField); } private void Bind(BindingManagerBase parentManager, string dataField) { Debug.Assert(parentManager != null, "How could this be a null parentManager."); this.parentManager = parentManager; this.dataField = dataField; this.fieldInfo = parentManager.GetItemProperties().Find(dataField, true); if (fieldInfo == null) throw new ArgumentException(SR.GetString(SR.RelatedListManagerChild, dataField)); // this.finalType = fieldInfo.PropertyType; parentManager.CurrentItemChanged += new EventHandler(ParentManager_CurrentItemChanged); Refresh(); } internal override string GetListName() { string name = GetListName(new ArrayList()); if (name.Length > 0) { return name; } return base.GetListName(); } protected internal override string GetListName(ArrayList listAccessors) { listAccessors.Insert(0, fieldInfo); return parentManager.GetListName(listAccessors); } internal override PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors) { PropertyDescriptor[] accessors; if (listAccessors != null && listAccessors.Length > 0) { accessors = new PropertyDescriptor[listAccessors.Length + 1]; listAccessors.CopyTo(accessors, 1); } else { accessors = new PropertyDescriptor[1]; } // Set this accessor (add to the beginning) accessors[0] = this.fieldInfo; // Get props return parentManager.GetItemProperties(accessors); } private void ParentManager_CurrentItemChanged(object sender, EventArgs e) { Refresh(); } private void Refresh() { EndCurrentEdit(); SetDataSource(GetCurrentOrNull(parentManager)); OnCurrentChanged(EventArgs.Empty); } internal override Type BindType { get { return fieldInfo.PropertyType; } } public override object Current { get { return (this.DataSource != null) ? fieldInfo.GetValue(this.DataSource) : null; } } static private object GetCurrentOrNull(BindingManagerBase parentManager) { bool anyCurrent = (parentManager.Position >= 0 && parentManager.Position < parentManager.Count); return anyCurrent ? parentManager.Current : null; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using System; using Microsoft.Win32; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.ComponentModel; using System.Collections; internal class RelatedPropertyManager : PropertyManager { BindingManagerBase parentManager; string dataField; PropertyDescriptor fieldInfo; [ SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors") // If the constructor does not set the dataSource // it would be a breaking change. ] internal RelatedPropertyManager(BindingManagerBase parentManager, string dataField) : base(GetCurrentOrNull(parentManager), dataField) { Bind(parentManager, dataField); } private void Bind(BindingManagerBase parentManager, string dataField) { Debug.Assert(parentManager != null, "How could this be a null parentManager."); this.parentManager = parentManager; this.dataField = dataField; this.fieldInfo = parentManager.GetItemProperties().Find(dataField, true); if (fieldInfo == null) throw new ArgumentException(SR.GetString(SR.RelatedListManagerChild, dataField)); // this.finalType = fieldInfo.PropertyType; parentManager.CurrentItemChanged += new EventHandler(ParentManager_CurrentItemChanged); Refresh(); } internal override string GetListName() { string name = GetListName(new ArrayList()); if (name.Length > 0) { return name; } return base.GetListName(); } protected internal override string GetListName(ArrayList listAccessors) { listAccessors.Insert(0, fieldInfo); return parentManager.GetListName(listAccessors); } internal override PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors) { PropertyDescriptor[] accessors; if (listAccessors != null && listAccessors.Length > 0) { accessors = new PropertyDescriptor[listAccessors.Length + 1]; listAccessors.CopyTo(accessors, 1); } else { accessors = new PropertyDescriptor[1]; } // Set this accessor (add to the beginning) accessors[0] = this.fieldInfo; // Get props return parentManager.GetItemProperties(accessors); } private void ParentManager_CurrentItemChanged(object sender, EventArgs e) { Refresh(); } private void Refresh() { EndCurrentEdit(); SetDataSource(GetCurrentOrNull(parentManager)); OnCurrentChanged(EventArgs.Empty); } internal override Type BindType { get { return fieldInfo.PropertyType; } } public override object Current { get { return (this.DataSource != null) ? fieldInfo.GetValue(this.DataSource) : null; } } static private object GetCurrentOrNull(BindingManagerBase parentManager) { bool anyCurrent = (parentManager.Position >= 0 && parentManager.Position < parentManager.Count); return anyCurrent ? parentManager.Current : null; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TextElementEditingBehaviorAttribute.cs
- UnmanagedBitmapWrapper.cs
- RichTextBoxAutomationPeer.cs
- HttpBrowserCapabilitiesWrapper.cs
- RawKeyboardInputReport.cs
- Image.cs
- _SpnDictionary.cs
- ThumbAutomationPeer.cs
- SiteMap.cs
- CodeTypeReference.cs
- ObjectListShowCommandsEventArgs.cs
- ReturnType.cs
- ObjectListDataBindEventArgs.cs
- SimpleExpression.cs
- SQLRoleProvider.cs
- LoadedEvent.cs
- PropertyPushdownHelper.cs
- HMAC.cs
- DBNull.cs
- StrokeFIndices.cs
- _SpnDictionary.cs
- UntrustedRecipientException.cs
- CurrentChangedEventManager.cs
- PolygonHotSpot.cs
- UIPropertyMetadata.cs
- __ComObject.cs
- AdapterDictionary.cs
- EarlyBoundInfo.cs
- IImplicitResourceProvider.cs
- QueryComponents.cs
- DrawingContext.cs
- ElementProxy.cs
- SqlBuilder.cs
- ProcessModuleCollection.cs
- RunWorkerCompletedEventArgs.cs
- XslAstAnalyzer.cs
- GradientSpreadMethodValidation.cs
- NCryptSafeHandles.cs
- XmlElementList.cs
- PresentationAppDomainManager.cs
- WebPartCancelEventArgs.cs
- WpfWebRequestHelper.cs
- SchemaType.cs
- CalloutQueueItem.cs
- BooleanFacetDescriptionElement.cs
- DataRelation.cs
- ImageCollectionCodeDomSerializer.cs
- MultiBinding.cs
- CommandID.cs
- SQLUtility.cs
- BitConverter.cs
- UiaCoreApi.cs
- OutputCacheProfileCollection.cs
- WebPartsPersonalization.cs
- ConnectionStringSettings.cs
- SimpleHandlerFactory.cs
- XsdBuilder.cs
- Roles.cs
- DbSource.cs
- FillErrorEventArgs.cs
- DataColumnCollection.cs
- XmlMemberMapping.cs
- XmlDataCollection.cs
- SimpleTextLine.cs
- Enum.cs
- ColorBlend.cs
- Point3DCollectionConverter.cs
- CustomLineCap.cs
- Pointer.cs
- FloatSumAggregationOperator.cs
- XmlArrayItemAttribute.cs
- FrameworkContextData.cs
- OracleCommand.cs
- DebugManager.cs
- MsmqIntegrationMessagePool.cs
- ContentPresenter.cs
- XmlToDatasetMap.cs
- ResourcePermissionBaseEntry.cs
- DecimalKeyFrameCollection.cs
- PrimitiveCodeDomSerializer.cs
- CompilationUnit.cs
- ProfileService.cs
- SubstitutionDesigner.cs
- StateMachineHelpers.cs
- CorrelationValidator.cs
- RegexCompiler.cs
- COM2ExtendedBrowsingHandler.cs
- SelectorItemAutomationPeer.cs
- DetailsViewModeEventArgs.cs
- SRGSCompiler.cs
- ToolStripContextMenu.cs
- HandleRef.cs
- Quaternion.cs
- ModuleConfigurationInfo.cs
- MetabaseSettings.cs
- TracingConnection.cs
- SchemaCollectionPreprocessor.cs
- TypeConverterHelper.cs
- BindableAttribute.cs
- MTConfigUtil.cs