Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / CompMod / System / ComponentModel / ArrayConverter.cs / 1 / ArrayConverter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.ComponentModel { using Microsoft.Win32; using System.Collections; using System.Diagnostics; using System.Globalization; using System.Runtime.InteropServices; using System.Runtime.Remoting; using System.Runtime.Serialization.Formatters; using System.Security.Permissions; ////// [HostProtection(SharedState = true)] public class ArrayConverter : CollectionConverter { ///Provides a type converter to convert ////// objects to and from various other representations. /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(string)) { if (value is Array) { return SR.GetString(SR.ArrayConverterText, value.GetType().Name); } } return base.ConvertTo(context, culture, value, destinationType); } ///Converts the given value object to the specified destination type. ////// public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { PropertyDescriptor[] props = null; if (value.GetType().IsArray) { Array valueArray = (Array)value; int length = valueArray.GetLength(0); props = new PropertyDescriptor[length]; Type arrayType = value.GetType(); Type elementType = arrayType.GetElementType(); for (int i = 0; i < length; i++) { props[i] = new ArrayPropertyDescriptor(arrayType, elementType, i); } } return new PropertyDescriptorCollection(props); } ///Gets a collection of properties for the type of array /// specified by the value /// parameter. ////// public override bool GetPropertiesSupported(ITypeDescriptorContext context) { return true; } private class ArrayPropertyDescriptor : SimplePropertyDescriptor { private int index; public ArrayPropertyDescriptor(Type arrayType, Type elementType, int index) : base(arrayType, "[" + index + "]", elementType, null) { this.index = index; } public override object GetValue(object instance) { if (instance is Array) { Array array = (Array)instance; if (array.GetLength(0) > index) { return array.GetValue(index); } } return null; } public override void SetValue(object instance, object value) { if (instance is Array) { Array array = (Array)instance; if (array.GetLength(0) > index) { array.SetValue(value, index); } OnValueChanged(instance, EventArgs.Empty); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //Gets a value indicating whether this object /// supports properties. ///// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.ComponentModel { using Microsoft.Win32; using System.Collections; using System.Diagnostics; using System.Globalization; using System.Runtime.InteropServices; using System.Runtime.Remoting; using System.Runtime.Serialization.Formatters; using System.Security.Permissions; ////// [HostProtection(SharedState = true)] public class ArrayConverter : CollectionConverter { ///Provides a type converter to convert ////// objects to and from various other representations. /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(string)) { if (value is Array) { return SR.GetString(SR.ArrayConverterText, value.GetType().Name); } } return base.ConvertTo(context, culture, value, destinationType); } ///Converts the given value object to the specified destination type. ////// public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { PropertyDescriptor[] props = null; if (value.GetType().IsArray) { Array valueArray = (Array)value; int length = valueArray.GetLength(0); props = new PropertyDescriptor[length]; Type arrayType = value.GetType(); Type elementType = arrayType.GetElementType(); for (int i = 0; i < length; i++) { props[i] = new ArrayPropertyDescriptor(arrayType, elementType, i); } } return new PropertyDescriptorCollection(props); } ///Gets a collection of properties for the type of array /// specified by the value /// parameter. ////// public override bool GetPropertiesSupported(ITypeDescriptorContext context) { return true; } private class ArrayPropertyDescriptor : SimplePropertyDescriptor { private int index; public ArrayPropertyDescriptor(Type arrayType, Type elementType, int index) : base(arrayType, "[" + index + "]", elementType, null) { this.index = index; } public override object GetValue(object instance) { if (instance is Array) { Array array = (Array)instance; if (array.GetLength(0) > index) { return array.GetValue(index); } } return null; } public override void SetValue(object instance, object value) { if (instance is Array) { Array array = (Array)instance; if (array.GetLength(0) > index) { array.SetValue(value, index); } OnValueChanged(instance, EventArgs.Empty); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.Gets a value indicating whether this object /// supports properties. ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XPathAxisIterator.cs
- DataColumnCollection.cs
- ValueOfAction.cs
- HttpDictionary.cs
- SplitterPanel.cs
- NCryptSafeHandles.cs
- SharedConnectionInfo.cs
- XmlTextReaderImplHelpers.cs
- IsolatedStoragePermission.cs
- ToolstripProfessionalRenderer.cs
- RadioButtonFlatAdapter.cs
- ComponentTray.cs
- DataSpaceManager.cs
- KeyToListMap.cs
- ReadOnlyTernaryTree.cs
- MenuItemBinding.cs
- TypeInfo.cs
- ReadOnlyHierarchicalDataSourceView.cs
- NoPersistProperty.cs
- InternalTypeHelper.cs
- TypeConverterValueSerializer.cs
- NotSupportedException.cs
- ErrorsHelper.cs
- DataListComponentEditor.cs
- SpotLight.cs
- ListViewInsertionMark.cs
- Visitor.cs
- OdbcPermission.cs
- ZoneIdentityPermission.cs
- HitTestWithGeometryDrawingContextWalker.cs
- AttributeUsageAttribute.cs
- MenuBase.cs
- InputManager.cs
- TerminatorSinks.cs
- ListSortDescriptionCollection.cs
- ClassHandlersStore.cs
- Attributes.cs
- Int64.cs
- InertiaExpansionBehavior.cs
- WmlListAdapter.cs
- CompositionAdorner.cs
- TranslateTransform.cs
- FixedSOMPageConstructor.cs
- PriorityQueue.cs
- HistoryEventArgs.cs
- ClientTarget.cs
- PasswordTextContainer.cs
- SystemIcons.cs
- UnauthorizedAccessException.cs
- RichTextBox.cs
- UpdateCommand.cs
- EnumMember.cs
- FileAuthorizationModule.cs
- MasterPageBuildProvider.cs
- HtmlTableCellCollection.cs
- backend.cs
- HwndHost.cs
- FocusTracker.cs
- AssertSection.cs
- TextSyndicationContent.cs
- SimpleWorkerRequest.cs
- ResourceDisplayNameAttribute.cs
- MailAddressCollection.cs
- OdbcParameter.cs
- FixedSOMTable.cs
- AdornerLayer.cs
- ImageFormat.cs
- DataServiceProviderWrapper.cs
- ResourceReferenceExpression.cs
- KoreanCalendar.cs
- MasterPage.cs
- TextEffectResolver.cs
- KnowledgeBase.cs
- DragStartedEventArgs.cs
- LinkLabel.cs
- WindowsRegion.cs
- MsmqBindingFilter.cs
- QueryException.cs
- StreamWithDictionary.cs
- FontWeight.cs
- GlobalizationAssembly.cs
- NativeMethods.cs
- ThemeDictionaryExtension.cs
- DBConnection.cs
- MatrixTransform3D.cs
- BindingManagerDataErrorEventArgs.cs
- ListDictionary.cs
- CFStream.cs
- ToolStripItem.cs
- StreamResourceInfo.cs
- ReferenceTypeElement.cs
- Enum.cs
- XmlText.cs
- PackWebResponse.cs
- CallId.cs
- PrintDialogException.cs
- ActivationWorker.cs
- SchemaType.cs
- EnumUnknown.cs
- DesignerSerializationOptionsAttribute.cs