Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / WinForms / Managed / System / WinForms / PropertyGridInternal / ImmutablePropertyDescriptorGridEntry.cs / 1 / 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
- ListInitExpression.cs
- VisualTarget.cs
- ServicePointManager.cs
- SamlConditions.cs
- ParseElementCollection.cs
- SqlColumnizer.cs
- DataPagerField.cs
- SHA512Managed.cs
- _UriTypeConverter.cs
- TablePatternIdentifiers.cs
- JoinGraph.cs
- TextLineResult.cs
- GridViewUpdateEventArgs.cs
- TextViewSelectionProcessor.cs
- QuerySettings.cs
- Transform.cs
- RootBrowserWindow.cs
- SelectionPattern.cs
- DesignerTransactionCloseEvent.cs
- DataGridViewColumnTypePicker.cs
- SqlVersion.cs
- SafeViewOfFileHandle.cs
- TreeNodeClickEventArgs.cs
- HashAlgorithm.cs
- SyndicationFeed.cs
- AlignmentXValidation.cs
- DesignerSerializationOptionsAttribute.cs
- SRGSCompiler.cs
- TabControl.cs
- SupportsPreviewControlAttribute.cs
- LocalServiceSecuritySettingsElement.cs
- PersianCalendar.cs
- MemberDescriptor.cs
- ApplicationDirectory.cs
- TraceHandlerErrorFormatter.cs
- validationstate.cs
- SqlGatherProducedAliases.cs
- RpcCryptoRequest.cs
- Binding.cs
- SafeLocalAllocation.cs
- PageCatalogPart.cs
- Binding.cs
- MailWebEventProvider.cs
- ProxyElement.cs
- DataGridHeaderBorder.cs
- BoolLiteral.cs
- UnicastIPAddressInformationCollection.cs
- ProfilePropertySettings.cs
- ImportedPolicyConversionContext.cs
- BitmapPalette.cs
- PersonalizationState.cs
- CommandDevice.cs
- TraceUtility.cs
- X509IssuerSerialKeyIdentifierClause.cs
- PeerResolverBindingElement.cs
- ResourceDefaultValueAttribute.cs
- DbCommandDefinition.cs
- RenamedEventArgs.cs
- TimeSpanOrInfiniteValidator.cs
- UnhandledExceptionEventArgs.cs
- HostProtectionPermission.cs
- sqlpipe.cs
- RequiredAttributeAttribute.cs
- Command.cs
- SourceChangedEventArgs.cs
- User.cs
- UnsafeNativeMethods.cs
- FlowDocumentScrollViewerAutomationPeer.cs
- StylusPlugin.cs
- BitmapEffectrendercontext.cs
- ButtonBase.cs
- Drawing.cs
- Crc32.cs
- Pen.cs
- SessionIDManager.cs
- SmtpClient.cs
- TimeoutException.cs
- ElementNotAvailableException.cs
- Message.cs
- ResourceReferenceExpression.cs
- DBPropSet.cs
- TextTreeUndo.cs
- ValidateNames.cs
- EntityDataSourceViewSchema.cs
- XmlWriterTraceListener.cs
- FixedElement.cs
- Rule.cs
- StoreAnnotationsMap.cs
- FontUnitConverter.cs
- Qualifier.cs
- MimeTypePropertyAttribute.cs
- InlineCollection.cs
- SelectionGlyphBase.cs
- SerializationInfo.cs
- Int32Rect.cs
- TextWriterTraceListener.cs
- SourceFileBuildProvider.cs
- ArgumentOutOfRangeException.cs
- BuilderElements.cs
- QuadTree.cs