Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / WinForms / Managed / System / WinForms / ComponentModel / COM2Interop / COM2IDispatchConverter.cs / 1 / 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
- AssemblyAttributes.cs
- HtmlTernaryTree.cs
- KeyGestureConverter.cs
- SqlVersion.cs
- PageTheme.cs
- UIElementParaClient.cs
- ImageAutomationPeer.cs
- ProgressiveCrcCalculatingStream.cs
- GeometryGroup.cs
- SafeCloseHandleCritical.cs
- _ShellExpression.cs
- LexicalChunk.cs
- AccessedThroughPropertyAttribute.cs
- MenuItemBinding.cs
- ProjectionNode.cs
- EditingContext.cs
- BulletedListEventArgs.cs
- Viewport3DVisual.cs
- SettingsProperty.cs
- ListViewDeletedEventArgs.cs
- DataMisalignedException.cs
- HasCopySemanticsAttribute.cs
- WebPartDeleteVerb.cs
- _UriSyntax.cs
- SQLBytes.cs
- ServiceSettingsResponseInfo.cs
- ClipboardProcessor.cs
- SafeCertificateStore.cs
- CompilerParameters.cs
- Ray3DHitTestResult.cs
- TextBoxLine.cs
- CharConverter.cs
- OuterGlowBitmapEffect.cs
- EntityCommandCompilationException.cs
- TextControlDesigner.cs
- KerberosSecurityTokenProvider.cs
- LogEntrySerializer.cs
- MetabaseServerConfig.cs
- SignedXml.cs
- ButtonPopupAdapter.cs
- DataServices.cs
- SafeRightsManagementQueryHandle.cs
- XPathDocument.cs
- ComboBoxItem.cs
- _HelperAsyncResults.cs
- BindingElementCollection.cs
- HttpFileCollection.cs
- BinaryFormatter.cs
- RegexCompilationInfo.cs
- StringAnimationUsingKeyFrames.cs
- FrameworkObject.cs
- RouteItem.cs
- RightsManagementEncryptedStream.cs
- TypographyProperties.cs
- SlipBehavior.cs
- UxThemeWrapper.cs
- IRCollection.cs
- PropertyPathWorker.cs
- Formatter.cs
- Mappings.cs
- TextSyndicationContent.cs
- PersonalizationStateInfo.cs
- WebPartManagerInternals.cs
- MenuItemCollection.cs
- KnownTypesHelper.cs
- ScriptModule.cs
- GeometryValueSerializer.cs
- ResXDataNode.cs
- ResourceDictionaryCollection.cs
- ALinqExpressionVisitor.cs
- returneventsaver.cs
- XmlNodeChangedEventArgs.cs
- ScriptingJsonSerializationSection.cs
- ComboBoxAutomationPeer.cs
- securitycriticaldataClass.cs
- SqlCachedBuffer.cs
- DataGridGeneralPage.cs
- NativeMethods.cs
- NetworkInterface.cs
- LongValidator.cs
- ActivityBuilderHelper.cs
- PolicyManager.cs
- SafeEventLogReadHandle.cs
- ValidationUtility.cs
- ButtonField.cs
- TableLayoutStyle.cs
- SelectionProcessor.cs
- CdpEqualityComparer.cs
- MenuStrip.cs
- LabelDesigner.cs
- FilterableAttribute.cs
- GenericPrincipal.cs
- Reference.cs
- SimpleNameService.cs
- ProcessManager.cs
- SecurityChannelFaultConverter.cs
- X509Utils.cs
- BrowserDefinitionCollection.cs
- Page.cs
- RectangleGeometry.cs