Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / PropertyGridInternal / ImmutablePropertyDescriptorGridEntry.cs / 1305376 / ImmutablePropertyDescriptorGridEntry.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Windows.Forms.PropertyGridInternal { using System.Runtime.Serialization.Formatters; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System; using System.Collections; using System.Reflection; using System.ComponentModel; using System.ComponentModel.Design; using System.Windows.Forms; using System.Windows.Forms.Design; using System.Drawing; using System.Drawing.Design; using Microsoft.Win32; // This grid entry is used for immutable objects. An immutable object is identified // through it's TypeConverter, which returns TRUE to ShouldCreateInstance. For this case, // we never go through the property descriptor to change the value, but recreate each // time. // internal class ImmutablePropertyDescriptorGridEntry : PropertyDescriptorGridEntry { internal ImmutablePropertyDescriptorGridEntry(PropertyGrid ownerGrid, GridEntry peParent, PropertyDescriptor propInfo, bool hide) : base(ownerGrid, peParent, propInfo, hide) { } protected override bool IsPropertyReadOnly { get { return ShouldRenderReadOnly; } } public override object PropertyValue { get { return base.PropertyValue; } [SuppressMessage("Microsoft.Security", "CA2102:CatchNonClsCompliantExceptionsInGeneralHandlers")] set { // Create a new instance of the value and set it into the parent grid entry. // object owner = GetValueOwner(); GridEntry parentEntry = InstanceParentGridEntry; TypeConverter parentConverter = parentEntry.TypeConverter; PropertyDescriptorCollection props = parentConverter.GetProperties(parentEntry, owner); IDictionary values = new Hashtable(props.Count); object newObject = null; for (int i = 0; i < props.Count; i++) { if (propertyInfo.Name != null && propertyInfo.Name.Equals(props[i].Name)) { values[props[i].Name] = value; } else { values[props[i].Name] = props[i].GetValue(owner); } } try { newObject = parentConverter.CreateInstance(parentEntry, values); } catch (Exception e) { if (string.IsNullOrEmpty(e.Message)) { throw new TargetInvocationException(SR.GetString(SR.ExceptionCreatingObject, InstanceParentGridEntry.PropertyType.FullName, e.ToString()), e); } else throw; // rethrow the same exception } if (newObject != null) { parentEntry.PropertyValue = newObject; } } } internal override bool NotifyValueGivenParent(object obj, int type) { return ParentGridEntry.NotifyValue(type); } public override bool ShouldRenderReadOnly { get { return InstanceParentGridEntry.ShouldRenderReadOnly; } } private GridEntry InstanceParentGridEntry { get { GridEntry parent = this.ParentGridEntry; if (parent is CategoryGridEntry) { parent = parent.ParentGridEntry; } return parent; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Windows.Forms.PropertyGridInternal { using System.Runtime.Serialization.Formatters; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System; using System.Collections; using System.Reflection; using System.ComponentModel; using System.ComponentModel.Design; using System.Windows.Forms; using System.Windows.Forms.Design; using System.Drawing; using System.Drawing.Design; using Microsoft.Win32; // This grid entry is used for immutable objects. An immutable object is identified // through it's TypeConverter, which returns TRUE to ShouldCreateInstance. For this case, // we never go through the property descriptor to change the value, but recreate each // time. // internal class ImmutablePropertyDescriptorGridEntry : PropertyDescriptorGridEntry { internal ImmutablePropertyDescriptorGridEntry(PropertyGrid ownerGrid, GridEntry peParent, PropertyDescriptor propInfo, bool hide) : base(ownerGrid, peParent, propInfo, hide) { } protected override bool IsPropertyReadOnly { get { return ShouldRenderReadOnly; } } public override object PropertyValue { get { return base.PropertyValue; } [SuppressMessage("Microsoft.Security", "CA2102:CatchNonClsCompliantExceptionsInGeneralHandlers")] set { // Create a new instance of the value and set it into the parent grid entry. // object owner = GetValueOwner(); GridEntry parentEntry = InstanceParentGridEntry; TypeConverter parentConverter = parentEntry.TypeConverter; PropertyDescriptorCollection props = parentConverter.GetProperties(parentEntry, owner); IDictionary values = new Hashtable(props.Count); object newObject = null; for (int i = 0; i < props.Count; i++) { if (propertyInfo.Name != null && propertyInfo.Name.Equals(props[i].Name)) { values[props[i].Name] = value; } else { values[props[i].Name] = props[i].GetValue(owner); } } try { newObject = parentConverter.CreateInstance(parentEntry, values); } catch (Exception e) { if (string.IsNullOrEmpty(e.Message)) { throw new TargetInvocationException(SR.GetString(SR.ExceptionCreatingObject, InstanceParentGridEntry.PropertyType.FullName, e.ToString()), e); } else throw; // rethrow the same exception } if (newObject != null) { parentEntry.PropertyValue = newObject; } } } internal override bool NotifyValueGivenParent(object obj, int type) { return ParentGridEntry.NotifyValue(type); } public override bool ShouldRenderReadOnly { get { return InstanceParentGridEntry.ShouldRenderReadOnly; } } private GridEntry InstanceParentGridEntry { get { GridEntry parent = this.ParentGridEntry; if (parent is CategoryGridEntry) { parent = parent.ParentGridEntry; } return parent; } } } } // 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
- CodeGroup.cs
- CalendarTable.cs
- Transactions.cs
- VarRemapper.cs
- SchemaCollectionPreprocessor.cs
- LayoutSettings.cs
- FormatConvertedBitmap.cs
- AssemblyResourceLoader.cs
- ElementHostPropertyMap.cs
- SqlDependency.cs
- AuditLevel.cs
- HtmlCommandAdapter.cs
- WebBodyFormatMessageProperty.cs
- IpcPort.cs
- LogPolicy.cs
- WarningException.cs
- ProxyWebPart.cs
- Stylesheet.cs
- SubclassTypeValidator.cs
- AnnotationDocumentPaginator.cs
- NetSectionGroup.cs
- WebPartsSection.cs
- RuntimeIdentifierPropertyAttribute.cs
- EdmPropertyAttribute.cs
- TextDpi.cs
- WeakHashtable.cs
- ControlCachePolicy.cs
- ButtonChrome.cs
- ConfigUtil.cs
- LinkedResource.cs
- _NegotiateClient.cs
- ReflectionTypeLoadException.cs
- ReadOnlyHierarchicalDataSourceView.cs
- GenericEnumerator.cs
- ContextCorrelationInitializer.cs
- EasingQuaternionKeyFrame.cs
- WinCategoryAttribute.cs
- RightsManagementProvider.cs
- ipaddressinformationcollection.cs
- ArrayTypeMismatchException.cs
- BCLDebug.cs
- CodeTypeOfExpression.cs
- VerificationException.cs
- DispatcherObject.cs
- Script.cs
- IntranetCredentialPolicy.cs
- ColumnResizeUndoUnit.cs
- PartialTrustVisibleAssembly.cs
- EventKeyword.cs
- ExpressionConverter.cs
- Encoding.cs
- UIElementParagraph.cs
- QuaternionAnimationBase.cs
- StyleReferenceConverter.cs
- ResourceDefaultValueAttribute.cs
- HebrewNumber.cs
- EventSourceCreationData.cs
- DecoderFallback.cs
- CommonDialog.cs
- CategoryGridEntry.cs
- COM2ExtendedBrowsingHandler.cs
- SoapAttributeAttribute.cs
- SplitContainer.cs
- BinarySerializer.cs
- PointCollection.cs
- RefreshEventArgs.cs
- SiteMapDataSourceDesigner.cs
- FontNamesConverter.cs
- Selection.cs
- SqlDataSource.cs
- ArrangedElement.cs
- LayoutManager.cs
- MissingMethodException.cs
- WebPartZoneCollection.cs
- BamlTreeUpdater.cs
- ContextQuery.cs
- AsymmetricSignatureDeformatter.cs
- SafeNativeMethods.cs
- DecoderNLS.cs
- GlyphShapingProperties.cs
- CodeDomLoader.cs
- BadImageFormatException.cs
- RNGCryptoServiceProvider.cs
- CipherData.cs
- DataGridViewSelectedColumnCollection.cs
- InstanceDataCollection.cs
- BidirectionalDictionary.cs
- DbProviderConfigurationHandler.cs
- ProtocolsConfiguration.cs
- SplitterPanel.cs
- CompilationRelaxations.cs
- DataTransferEventArgs.cs
- NetworkInformationException.cs
- PreservationFileReader.cs
- ResizeBehavior.cs
- OdbcTransaction.cs
- FlatButtonAppearance.cs
- Endpoint.cs
- SimpleMailWebEventProvider.cs
- DetailsViewInsertEventArgs.cs