Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / WinForms / Managed / System / WinForms / TreeNodeConverter.cs / 1 / TreeNodeConverter.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; ////// /// TreeNodeConverter is a class that can be used to convert /// TreeNode objects from one data type to another. Access this /// class through the TypeDescriptor. /// public class TreeNodeConverter : TypeConverter { ////// /// 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 TreeNode) { TreeNode node = (TreeNode)value; MemberInfo info = null; object[] args = null; if (node.ImageIndex == -1 || node.SelectedImageIndex == -1) { if (node.Nodes.Count == 0) { info = typeof(TreeNode).GetConstructor(new Type[] {typeof(string)}); args = new object[] {node.Text}; } else { info = typeof(TreeNode).GetConstructor(new Type[] {typeof(string), typeof(TreeNode[])}); TreeNode[] nodesArray = new TreeNode[node.Nodes.Count]; node.Nodes.CopyTo(nodesArray, 0); args = new object[] {node.Text, nodesArray}; } } else { if (node.Nodes.Count == 0) { info = typeof(TreeNode).GetConstructor(new Type[] { typeof(string), typeof(int), typeof(int)}); args = new object[] { node.Text, node.ImageIndex, node.SelectedImageIndex}; } else { info = typeof(TreeNode).GetConstructor(new Type[] { typeof(string), typeof(int), typeof(int), typeof(TreeNode[])}); TreeNode[] nodesArray = new TreeNode[node.Nodes.Count]; node.Nodes.CopyTo(nodesArray, 0); args = new object[] { node.Text, node.ImageIndex, node.SelectedImageIndex, nodesArray}; } } if (info != null) { return new InstanceDescriptor(info, args, false); } } 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; ////// /// TreeNodeConverter is a class that can be used to convert /// TreeNode objects from one data type to another. Access this /// class through the TypeDescriptor. /// public class TreeNodeConverter : TypeConverter { ////// /// 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 TreeNode) { TreeNode node = (TreeNode)value; MemberInfo info = null; object[] args = null; if (node.ImageIndex == -1 || node.SelectedImageIndex == -1) { if (node.Nodes.Count == 0) { info = typeof(TreeNode).GetConstructor(new Type[] {typeof(string)}); args = new object[] {node.Text}; } else { info = typeof(TreeNode).GetConstructor(new Type[] {typeof(string), typeof(TreeNode[])}); TreeNode[] nodesArray = new TreeNode[node.Nodes.Count]; node.Nodes.CopyTo(nodesArray, 0); args = new object[] {node.Text, nodesArray}; } } else { if (node.Nodes.Count == 0) { info = typeof(TreeNode).GetConstructor(new Type[] { typeof(string), typeof(int), typeof(int)}); args = new object[] { node.Text, node.ImageIndex, node.SelectedImageIndex}; } else { info = typeof(TreeNode).GetConstructor(new Type[] { typeof(string), typeof(int), typeof(int), typeof(TreeNode[])}); TreeNode[] nodesArray = new TreeNode[node.Nodes.Count]; node.Nodes.CopyTo(nodesArray, 0); args = new object[] { node.Text, node.ImageIndex, node.SelectedImageIndex, nodesArray}; } } if (info != null) { return new InstanceDescriptor(info, args, false); } } 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
- System.Data_BID.cs
- SqlVersion.cs
- PeerObject.cs
- MulticastOption.cs
- LabelLiteral.cs
- NoPersistHandle.cs
- AutoSizeComboBox.cs
- SafeLibraryHandle.cs
- SafeRightsManagementHandle.cs
- TreeNodeStyleCollection.cs
- FastPropertyAccessor.cs
- WindowsListViewGroup.cs
- TypeDelegator.cs
- HtmlInputHidden.cs
- ObjectRef.cs
- UnsafeNativeMethods.cs
- HandoffBehavior.cs
- PackageDigitalSignature.cs
- EncoderParameter.cs
- SymbolType.cs
- ViewBase.cs
- CollectionDataContract.cs
- XmlSchemaAttributeGroupRef.cs
- XPathPatternBuilder.cs
- SafeFindHandle.cs
- SecurityProtocolFactory.cs
- PerformanceCounterLib.cs
- GroupedContextMenuStrip.cs
- InitiatorServiceModelSecurityTokenRequirement.cs
- ServiceChannelFactory.cs
- DesignerActionGlyph.cs
- HttpCacheVary.cs
- HttpCacheVary.cs
- BrushMappingModeValidation.cs
- ImportedNamespaceContextItem.cs
- XPathNavigatorReader.cs
- Inflater.cs
- SafeCryptoKeyHandle.cs
- SecurityManager.cs
- NativeObjectSecurity.cs
- FacetDescription.cs
- SmiRequestExecutor.cs
- InternalResources.cs
- DynamicDocumentPaginator.cs
- _HTTPDateParse.cs
- ServiceObjectContainer.cs
- SqlSelectStatement.cs
- FormatConvertedBitmap.cs
- DBDataPermission.cs
- BreakRecordTable.cs
- LabelLiteral.cs
- SymbolType.cs
- NamespaceImport.cs
- ProfilePropertySettings.cs
- BindingWorker.cs
- LogStore.cs
- ProfileServiceManager.cs
- ScriptManagerProxy.cs
- Point4D.cs
- ActivationArguments.cs
- ReferenceService.cs
- HierarchicalDataBoundControl.cs
- RuleInfoComparer.cs
- RemoteWebConfigurationHostServer.cs
- CalendarDayButton.cs
- UnsafeNativeMethodsMilCoreApi.cs
- SafeLibraryHandle.cs
- CounterSetInstance.cs
- x509store.cs
- CorrelationResolver.cs
- CngKeyCreationParameters.cs
- FamilyCollection.cs
- AsyncOperation.cs
- InvokeHandlers.cs
- ConnectionStringsExpressionEditor.cs
- RangeValueProviderWrapper.cs
- IdentifierService.cs
- DynamicILGenerator.cs
- StreamedWorkflowDefinitionContext.cs
- ExpressionBuilderContext.cs
- MultiView.cs
- ActionFrame.cs
- CallbackValidator.cs
- TraceHwndHost.cs
- oledbmetadatacollectionnames.cs
- ObjectContext.cs
- PolyBezierSegment.cs
- SqlProvider.cs
- PrimaryKeyTypeConverter.cs
- VideoDrawing.cs
- HttpModulesSection.cs
- InternalResources.cs
- ExpressionBuilderContext.cs
- DataServiceSaveChangesEventArgs.cs
- DetailsViewRow.cs
- OrderByQueryOptionExpression.cs
- Errors.cs
- httpserverutility.cs
- ColumnMapVisitor.cs
- TaiwanLunisolarCalendar.cs