Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- ConfigurationManagerHelper.cs
- RowUpdatedEventArgs.cs
- DesignerActionMethodItem.cs
- cookie.cs
- ModelPropertyDescriptor.cs
- sqlser.cs
- ObjectParameterCollection.cs
- Vector3D.cs
- AsyncStreamReader.cs
- RawStylusActions.cs
- GPRECTF.cs
- FontResourceCache.cs
- DefaultPropertyAttribute.cs
- VirtualPathUtility.cs
- DragEventArgs.cs
- Function.cs
- MaterializeFromAtom.cs
- VideoDrawing.cs
- CurrentChangedEventManager.cs
- XmlChildEnumerator.cs
- ProgressiveCrcCalculatingStream.cs
- BinaryObjectWriter.cs
- XmlSchemaInferenceException.cs
- EntitySetDataBindingList.cs
- QilBinary.cs
- XmlSortKeyAccumulator.cs
- SafeCancelMibChangeNotify.cs
- ElementInit.cs
- UIElementCollection.cs
- ToolstripProfessionalRenderer.cs
- PagedControl.cs
- RequestCachePolicyConverter.cs
- LineServicesRun.cs
- CmsInterop.cs
- SerializerDescriptor.cs
- HtmlFormParameterWriter.cs
- LassoSelectionBehavior.cs
- KeyedCollection.cs
- Crc32.cs
- XmlSchemaComplexContentRestriction.cs
- TextTreeFixupNode.cs
- CodeCompileUnit.cs
- _HeaderInfo.cs
- FileDialogCustomPlacesCollection.cs
- UIPermission.cs
- DialogWindow.cs
- DataGrid.cs
- StylusPlugin.cs
- RSACryptoServiceProvider.cs
- WMIGenerator.cs
- MobileTextWriter.cs
- TableLayout.cs
- COSERVERINFO.cs
- ADMembershipProvider.cs
- SystemWebSectionGroup.cs
- AssemblyNameEqualityComparer.cs
- SQLSingle.cs
- PriorityRange.cs
- EmptyEnumerator.cs
- XsltFunctions.cs
- WizardStepCollectionEditor.cs
- Point.cs
- SignatureGenerator.cs
- ProfilePropertySettings.cs
- PhysicalAddress.cs
- OleDbConnection.cs
- DataControlFieldCell.cs
- DataControlCommands.cs
- Profiler.cs
- GuidelineCollection.cs
- SplitContainer.cs
- NominalTypeEliminator.cs
- DeclarativeCatalogPart.cs
- XmlAttributeAttribute.cs
- TrackPointCollection.cs
- EntityParameterCollection.cs
- CheckBoxFlatAdapter.cs
- EventProviderBase.cs
- CodeArrayIndexerExpression.cs
- SvcMapFile.cs
- WebConfigurationHost.cs
- Wizard.cs
- RedirectionProxy.cs
- Enum.cs
- ChannelDispatcherCollection.cs
- ExtenderControl.cs
- TypeDelegator.cs
- OrthographicCamera.cs
- XmlQueryType.cs
- InputProviderSite.cs
- DoubleStorage.cs
- KeyGestureConverter.cs
- InputProcessorProfiles.cs
- ScaleTransform3D.cs
- AstTree.cs
- SpellCheck.cs
- SchemaAttDef.cs
- ListBase.cs
- UsernameTokenFactoryCredential.cs
- BlurEffect.cs