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
- XMLDiffLoader.cs
- RecipientIdentity.cs
- CommentAction.cs
- KeyValuePair.cs
- XmlWellformedWriterHelpers.cs
- RichTextBox.cs
- mda.cs
- WindowHideOrCloseTracker.cs
- WindowsGrip.cs
- ListBoxItemWrapperAutomationPeer.cs
- InProcStateClientManager.cs
- MetadataCache.cs
- ReadOnlyObservableCollection.cs
- Math.cs
- FamilyCollection.cs
- DataGridTableCollection.cs
- WinEventHandler.cs
- XmlSchemaSimpleTypeRestriction.cs
- NotConverter.cs
- ServiceModelEnhancedConfigurationElementCollection.cs
- CanonicalXml.cs
- GridPatternIdentifiers.cs
- NamespaceListProperty.cs
- SqlTriggerContext.cs
- SafeArrayRankMismatchException.cs
- ConditionalExpression.cs
- SelectionPattern.cs
- odbcmetadatacollectionnames.cs
- HostingEnvironmentException.cs
- WebPartConnectionCollection.cs
- StructuredTypeEmitter.cs
- AsyncResult.cs
- DBSqlParserColumn.cs
- connectionpool.cs
- SharedStatics.cs
- SoapSchemaExporter.cs
- SqlNotificationEventArgs.cs
- DataGridItemCollection.cs
- ReferentialConstraint.cs
- DesignerObject.cs
- MenuCommandsChangedEventArgs.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- SHA384.cs
- ThrowHelper.cs
- CodeDirectionExpression.cs
- RIPEMD160.cs
- BindingCollection.cs
- EntityDataSource.cs
- OleTxTransaction.cs
- grammarelement.cs
- StateMachine.cs
- StorageAssociationTypeMapping.cs
- Util.cs
- PropertyMapper.cs
- XmlValueConverter.cs
- ConnectionProviderAttribute.cs
- DrawListViewColumnHeaderEventArgs.cs
- FilteredDataSetHelper.cs
- LayoutTable.cs
- AppDomainManager.cs
- FontResourceCache.cs
- DataServiceQueryProvider.cs
- ThreadStateException.cs
- CaseInsensitiveHashCodeProvider.cs
- ReferenceCountedObject.cs
- XamlVector3DCollectionSerializer.cs
- ExtenderControl.cs
- SafeRightsManagementPubHandle.cs
- AnonymousIdentificationSection.cs
- ClientTargetSection.cs
- OpenTypeLayout.cs
- EmptyElement.cs
- SystemIPv6InterfaceProperties.cs
- Parameter.cs
- SetIterators.cs
- HtmlWindow.cs
- DeploymentExceptionMapper.cs
- TextBoxBaseDesigner.cs
- LightweightCodeGenerator.cs
- WebPart.cs
- InternalTypeHelper.cs
- NestPullup.cs
- BitmapEffectGeneralTransform.cs
- HttpDictionary.cs
- DecimalMinMaxAggregationOperator.cs
- WebPartZoneDesigner.cs
- EntityDataSourceWizardForm.cs
- DefaultParameterValueAttribute.cs
- TextInfo.cs
- FontFamilyConverter.cs
- MetadataArtifactLoaderComposite.cs
- ConnectionConsumerAttribute.cs
- WebPartExportVerb.cs
- InstanceNotReadyException.cs
- ContravarianceAdapter.cs
- Bits.cs
- FixedElement.cs
- Perspective.cs
- FindProgressChangedEventArgs.cs
- ConfigLoader.cs