Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / ComponentModel / COM2Interop / COM2IDispatchConverter.cs / 1305376 / COM2IDispatchConverter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms.ComponentModel.Com2Interop { using System.Diagnostics; using System; using System.ComponentModel; using System.Collections; using Microsoft.Win32; using System.Globalization; internal class Com2IDispatchConverter : Com2ExtendedTypeConverter{ Com2PropertyDescriptor propDesc; ////// /// What we return textually for null. /// protected static readonly string none = SR.GetString(SR.toStringNone); private bool allowExpand; public Com2IDispatchConverter(Com2PropertyDescriptor propDesc, bool allowExpand, TypeConverter baseConverter) : base(baseConverter){ this.propDesc = propDesc; this.allowExpand = allowExpand; } public Com2IDispatchConverter(Com2PropertyDescriptor propDesc, bool allowExpand) : base(propDesc.PropertyType){ this.propDesc = propDesc; this.allowExpand = allowExpand; } ////// /// Determines if this converter can convert an object in the given source /// type to the native type of the converter. /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return false; } ////// /// Determines if this converter can convert an object to the given destination /// type. /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { return destinationType == typeof(string); } ////// /// Converts the given object to another type. The most common types to convert /// are to and from a string object. The default implementation will make a call /// to ToString on the object if the object is valid and if the destination /// type is string. If this cannot convert to the desitnation type, this will /// throw a NotSupportedException. /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string)){ if (value == null){ return none; } string text = ComNativeDescriptor.Instance.GetName(value); if (text == null || text.Length == 0){ text = ComNativeDescriptor.Instance.GetClassName(value); } if (text == null){ return "(Object)"; } return text; } return base.ConvertTo(context, culture, value, destinationType); } public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { return TypeDescriptor.GetProperties(value, attributes); } ////// /// Determines if this object supports properties. By default, this /// is false. /// public override bool GetPropertiesSupported(ITypeDescriptorContext context) { return this.allowExpand; } // no dropdown, please! // public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms.ComponentModel.Com2Interop { using System.Diagnostics; using System; using System.ComponentModel; using System.Collections; using Microsoft.Win32; using System.Globalization; internal class Com2IDispatchConverter : Com2ExtendedTypeConverter{ Com2PropertyDescriptor propDesc; ////// /// What we return textually for null. /// protected static readonly string none = SR.GetString(SR.toStringNone); private bool allowExpand; public Com2IDispatchConverter(Com2PropertyDescriptor propDesc, bool allowExpand, TypeConverter baseConverter) : base(baseConverter){ this.propDesc = propDesc; this.allowExpand = allowExpand; } public Com2IDispatchConverter(Com2PropertyDescriptor propDesc, bool allowExpand) : base(propDesc.PropertyType){ this.propDesc = propDesc; this.allowExpand = allowExpand; } ////// /// Determines if this converter can convert an object in the given source /// type to the native type of the converter. /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return false; } ////// /// Determines if this converter can convert an object to the given destination /// type. /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { return destinationType == typeof(string); } ////// /// Converts the given object to another type. The most common types to convert /// are to and from a string object. The default implementation will make a call /// to ToString on the object if the object is valid and if the destination /// type is string. If this cannot convert to the desitnation type, this will /// throw a NotSupportedException. /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string)){ if (value == null){ return none; } string text = ComNativeDescriptor.Instance.GetName(value); if (text == null || text.Length == 0){ text = ComNativeDescriptor.Instance.GetClassName(value); } if (text == null){ return "(Object)"; } return text; } return base.ConvertTo(context, culture, value, destinationType); } public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { return TypeDescriptor.GetProperties(value, attributes); } ////// /// Determines if this object supports properties. By default, this /// is false. /// public override bool GetPropertiesSupported(ITypeDescriptorContext context) { return this.allowExpand; } // no dropdown, please! // public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return false; } } } // 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
- WorkflowFileItem.cs
- XpsFixedPageReaderWriter.cs
- SelectionRangeConverter.cs
- WmlMobileTextWriter.cs
- ScrollItemPattern.cs
- SubpageParaClient.cs
- ConsoleCancelEventArgs.cs
- CodeComment.cs
- DocumentGrid.cs
- TranslateTransform.cs
- BaseCodePageEncoding.cs
- SqlClientPermission.cs
- TemplatePropertyEntry.cs
- SettingsPropertyValueCollection.cs
- EmptyStringExpandableObjectConverter.cs
- PeerInvitationResponse.cs
- CqlQuery.cs
- MonitorWrapper.cs
- SafeArchiveContext.cs
- SettingsPropertyCollection.cs
- XmlSerializer.cs
- SelectionService.cs
- HostedHttpContext.cs
- FaultContractInfo.cs
- DictionarySectionHandler.cs
- ContextQuery.cs
- EmptyImpersonationContext.cs
- MultiPageTextView.cs
- FontDifferentiator.cs
- BooleanStorage.cs
- And.cs
- DependencyProperty.cs
- EllipseGeometry.cs
- StaticDataManager.cs
- FormatterServices.cs
- WpfGeneratedKnownProperties.cs
- Native.cs
- CatalogPartChrome.cs
- Symbol.cs
- Rule.cs
- AttributeParameterInfo.cs
- HttpRawResponse.cs
- DataGridViewAutoSizeModeEventArgs.cs
- XmlNodeList.cs
- ArrayElementGridEntry.cs
- PromptStyle.cs
- TextElementEnumerator.cs
- DateTimeFormatInfo.cs
- CodeDirectionExpression.cs
- RemoteWebConfigurationHostStream.cs
- IDReferencePropertyAttribute.cs
- ResXResourceSet.cs
- IndentTextWriter.cs
- MinimizableAttributeTypeConverter.cs
- ListViewItemSelectionChangedEvent.cs
- EmptyEnumerator.cs
- DataGridLinkButton.cs
- TypeListConverter.cs
- PublisherIdentityPermission.cs
- ContextBase.cs
- HitTestParameters3D.cs
- GeometryDrawing.cs
- SchemaImporterExtension.cs
- TdsParameterSetter.cs
- RemoteWebConfigurationHostStream.cs
- ManipulationLogic.cs
- XPathParser.cs
- DataGridCommandEventArgs.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- ExpressionBuilder.cs
- HttpCachePolicyWrapper.cs
- FormsAuthenticationTicket.cs
- SqlBuffer.cs
- DesignerActionPropertyItem.cs
- LocalBuilder.cs
- DataControlLinkButton.cs
- FloaterParagraph.cs
- NullReferenceException.cs
- EventLogPermissionAttribute.cs
- ExtensionWindowHeader.cs
- ExpandedWrapper.cs
- ProfileGroupSettings.cs
- Button.cs
- BridgeDataReader.cs
- GridViewSelectEventArgs.cs
- SqlDependencyListener.cs
- Logging.cs
- TextBoxDesigner.cs
- ExpressionNormalizer.cs
- ToolStripItemImageRenderEventArgs.cs
- FrameworkElement.cs
- Slider.cs
- NestedContainer.cs
- EmbeddedObject.cs
- Unit.cs
- WebBaseEventKeyComparer.cs
- DetectRunnableInstancesTask.cs
- AnnotationHelper.cs
- CharacterString.cs
- TextEditorParagraphs.cs