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
- NotImplementedException.cs
- TreeNodeEventArgs.cs
- Parser.cs
- FormViewInsertEventArgs.cs
- AdapterUtil.cs
- DefaultObjectMappingItemCollection.cs
- DataObject.cs
- GeneralTransformGroup.cs
- FolderBrowserDialogDesigner.cs
- TreeViewEvent.cs
- PageWrapper.cs
- Stylus.cs
- GlobalizationAssembly.cs
- TemplateInstanceAttribute.cs
- ThreadPool.cs
- StaticSiteMapProvider.cs
- HtmlMeta.cs
- HashAlgorithm.cs
- Durable.cs
- TemplateAction.cs
- FrameworkContentElement.cs
- XmlWellformedWriter.cs
- RealProxy.cs
- ConfigXmlSignificantWhitespace.cs
- MatrixAnimationUsingKeyFrames.cs
- processwaithandle.cs
- UndirectedGraph.cs
- ZipIOExtraFieldZip64Element.cs
- FileClassifier.cs
- HttpCapabilitiesEvaluator.cs
- IpcServerChannel.cs
- CellRelation.cs
- Span.cs
- PageStatePersister.cs
- UseLicense.cs
- SuspendDesigner.cs
- DataGridViewCellPaintingEventArgs.cs
- FunctionCommandText.cs
- Inflater.cs
- PasswordRecovery.cs
- WpfWebRequestHelper.cs
- SmiTypedGetterSetter.cs
- ReferentialConstraint.cs
- PropertyTab.cs
- RtType.cs
- Separator.cs
- WebControl.cs
- BamlLocalizer.cs
- LookupBindingPropertiesAttribute.cs
- CheckedListBox.cs
- FrameworkElementAutomationPeer.cs
- FilterElement.cs
- ThrowHelper.cs
- WorkflowInstanceExtensionManager.cs
- BufferedReadStream.cs
- TypeExtensionConverter.cs
- ObfuscateAssemblyAttribute.cs
- IgnoreFileBuildProvider.cs
- WhitespaceSignificantCollectionAttribute.cs
- Composition.cs
- DynamicValueConverter.cs
- DynamicResourceExtension.cs
- ConfigurationProperty.cs
- MainMenu.cs
- ApplicationDirectory.cs
- SchemeSettingElementCollection.cs
- GenerateScriptTypeAttribute.cs
- DataBinder.cs
- XmlValidatingReader.cs
- LinqDataSourceValidationException.cs
- XmlElementElementCollection.cs
- SQLInt64Storage.cs
- EntryWrittenEventArgs.cs
- CorrelationActionMessageFilter.cs
- PeerNearMe.cs
- ExtensionSurface.cs
- AuthorizationContext.cs
- WhileDesigner.xaml.cs
- TextCharacters.cs
- QilChoice.cs
- MDIControlStrip.cs
- MailWriter.cs
- ImageConverter.cs
- ScrollItemProviderWrapper.cs
- XmlDownloadManager.cs
- Selector.cs
- SpnegoTokenProvider.cs
- Compiler.cs
- PositiveTimeSpanValidatorAttribute.cs
- DataGridViewHeaderCell.cs
- BoundColumn.cs
- DomainLiteralReader.cs
- BaseTemplateBuildProvider.cs
- TimestampInformation.cs
- ObjectContextServiceProvider.cs
- NativeMethods.cs
- PageAsyncTask.cs
- Link.cs
- PolyBezierSegmentFigureLogic.cs
- DataObjectEventArgs.cs