Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / ColumnHeaderConverter.cs / 1305376 / ColumnHeaderConverter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Windows.Forms { using System.Runtime.Serialization.Formatters; using System.Runtime.Remoting; using System.Runtime.InteropServices; using Microsoft.Win32; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Drawing; using System.Diagnostics; using System.Globalization; using System.Reflection; ////// /// public class ColumnHeaderConverter : ExpandableObjectConverter { ////// /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) { return true; } return base.CanConvertTo(context, destinationType); } ///Gets a value indicating whether this converter can /// convert an object to the given destination type using the context. ////// /// 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 == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(InstanceDescriptor) && value is ColumnHeader) { ColumnHeader col = (ColumnHeader) value; ConstructorInfo ctor; Type t = TypeDescriptor.GetReflectionType(value); InstanceDescriptor id = null; if (col.ImageIndex != -1) { ctor = t.GetConstructor(new Type[]{typeof(int)}); if (ctor != null) { id = new InstanceDescriptor(ctor, new object[]{col.ImageIndex}, false); } } if (id == null && !String.IsNullOrEmpty(col.ImageKey)) { ctor = t.GetConstructor(new Type[]{typeof(string)}); if (ctor != null) { id = new InstanceDescriptor(ctor, new object[]{col.ImageKey}, false); } } if (id == null) { ctor = t.GetConstructor(new Type[0]); if (ctor != null) { return new InstanceDescriptor(ctor, new object[0], false); } else { throw new ArgumentException(SR.GetString(SR.NoDefaultConstructor, t.FullName)); } } return id; } return base.ConvertTo(context, culture, value, destinationType); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Windows.Forms { using System.Runtime.Serialization.Formatters; using System.Runtime.Remoting; using System.Runtime.InteropServices; using Microsoft.Win32; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Drawing; using System.Diagnostics; using System.Globalization; using System.Reflection; ////// /// public class ColumnHeaderConverter : ExpandableObjectConverter { ////// /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) { return true; } return base.CanConvertTo(context, destinationType); } ///Gets a value indicating whether this converter can /// convert an object to the given destination type using the context. ////// /// 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 == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(InstanceDescriptor) && value is ColumnHeader) { ColumnHeader col = (ColumnHeader) value; ConstructorInfo ctor; Type t = TypeDescriptor.GetReflectionType(value); InstanceDescriptor id = null; if (col.ImageIndex != -1) { ctor = t.GetConstructor(new Type[]{typeof(int)}); if (ctor != null) { id = new InstanceDescriptor(ctor, new object[]{col.ImageIndex}, false); } } if (id == null && !String.IsNullOrEmpty(col.ImageKey)) { ctor = t.GetConstructor(new Type[]{typeof(string)}); if (ctor != null) { id = new InstanceDescriptor(ctor, new object[]{col.ImageKey}, false); } } if (id == null) { ctor = t.GetConstructor(new Type[0]); if (ctor != null) { return new InstanceDescriptor(ctor, new object[0], false); } else { throw new ArgumentException(SR.GetString(SR.NoDefaultConstructor, t.FullName)); } } return id; } return base.ConvertTo(context, culture, value, destinationType); } } } // 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
- ObjectSet.cs
- PolicyDesigner.cs
- DataGridDesigner.cs
- KeyConstraint.cs
- DataControlButton.cs
- PhonemeConverter.cs
- TypeDescriptionProvider.cs
- PreviewKeyDownEventArgs.cs
- CookieParameter.cs
- ListenerSessionConnectionReader.cs
- DataPagerFieldCommandEventArgs.cs
- SignatureHelper.cs
- SerialErrors.cs
- StretchValidation.cs
- List.cs
- TagPrefixInfo.cs
- UnsupportedPolicyOptionsException.cs
- CompositeTypefaceMetrics.cs
- MetaData.cs
- ObjectStorage.cs
- Model3DGroup.cs
- XmlDocumentFragment.cs
- ColumnResult.cs
- ReferenceTypeElement.cs
- SystemParameters.cs
- DropSource.cs
- StickyNoteHelper.cs
- Deserializer.cs
- WebPartCollection.cs
- DelegatingConfigHost.cs
- DataSourceCache.cs
- ProviderIncompatibleException.cs
- ThreadPool.cs
- SqlConnectionPoolProviderInfo.cs
- EntityContainerEntitySetDefiningQuery.cs
- StylusButton.cs
- FixUpCollection.cs
- SqlRetyper.cs
- MarkupObject.cs
- LinearGradientBrush.cs
- TextParaClient.cs
- SessionEndingCancelEventArgs.cs
- XsltCompileContext.cs
- ListBindingConverter.cs
- EncryptedData.cs
- ValidationSummary.cs
- CacheAxisQuery.cs
- VectorKeyFrameCollection.cs
- DashStyle.cs
- ControlIdConverter.cs
- SafeFileMappingHandle.cs
- ServiceObjectContainer.cs
- FontFamilyConverter.cs
- DetailsViewModeEventArgs.cs
- ReferenceSchema.cs
- UiaCoreApi.cs
- HttpModule.cs
- EncodingNLS.cs
- StrokeIntersection.cs
- HostedElements.cs
- BinaryReader.cs
- FlowLayoutPanelDesigner.cs
- ObjectMemberMapping.cs
- TableParaClient.cs
- Codec.cs
- Constants.cs
- CheckBoxList.cs
- ParameterElement.cs
- ConstNode.cs
- ClosableStream.cs
- Oci.cs
- X509Certificate2Collection.cs
- ContextMenu.cs
- BindingManagerDataErrorEventArgs.cs
- COM2PropertyDescriptor.cs
- BuildProvidersCompiler.cs
- Matrix.cs
- PageCatalogPart.cs
- TraceSection.cs
- AsyncOperationManager.cs
- ZipFileInfoCollection.cs
- StructureChangedEventArgs.cs
- WindowCollection.cs
- DateTimeValueSerializerContext.cs
- AbstractSvcMapFileLoader.cs
- SortDescriptionCollection.cs
- HighlightVisual.cs
- cryptoapiTransform.cs
- DataControlCommands.cs
- LineSegment.cs
- XmlReflectionImporter.cs
- DataColumnMapping.cs
- IPEndPointCollection.cs
- EnumerableRowCollection.cs
- securitycriticaldata.cs
- DataGridViewTextBoxEditingControl.cs
- MulticastOption.cs
- MouseActionConverter.cs
- ColumnBinding.cs
- ImageButton.cs