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
- PassportAuthenticationModule.cs
- StringConcat.cs
- PrinterUnitConvert.cs
- DbConnectionHelper.cs
- LocationUpdates.cs
- CorePropertiesFilter.cs
- SecurityHelper.cs
- FixedSOMFixedBlock.cs
- XmlSerializer.cs
- ColumnWidthChangingEvent.cs
- StringSource.cs
- XmlMembersMapping.cs
- PointHitTestResult.cs
- ObjectListSelectEventArgs.cs
- TokenizerHelper.cs
- TypeListConverter.cs
- DbException.cs
- SharedConnectionInfo.cs
- TypeValidationEventArgs.cs
- BamlResourceContent.cs
- ValidationErrorCollection.cs
- HtmlProps.cs
- SizeAnimationUsingKeyFrames.cs
- PageStatePersister.cs
- QuaternionAnimationUsingKeyFrames.cs
- WeakReferenceEnumerator.cs
- PolyLineSegmentFigureLogic.cs
- XmlSchemaGroup.cs
- EdgeModeValidation.cs
- RefreshPropertiesAttribute.cs
- ColumnResizeUndoUnit.cs
- RegexGroup.cs
- StringInfo.cs
- InputLanguageSource.cs
- precedingquery.cs
- FreezableOperations.cs
- AuthenticationModuleElement.cs
- DataBindingValueUIHandler.cs
- SqlCommandBuilder.cs
- ResourceAssociationSetEnd.cs
- Matrix.cs
- Cell.cs
- RowUpdatingEventArgs.cs
- PropertyCollection.cs
- ContravarianceAdapter.cs
- Pair.cs
- SwitchAttribute.cs
- RuntimeArgumentHandle.cs
- CompilerResults.cs
- TokenizerHelper.cs
- SHA1CryptoServiceProvider.cs
- Window.cs
- ToolStripContainerDesigner.cs
- DbSourceParameterCollection.cs
- XPathNavigator.cs
- TableColumn.cs
- NullableDecimalMinMaxAggregationOperator.cs
- ShortcutKeysEditor.cs
- httpapplicationstate.cs
- IntMinMaxAggregationOperator.cs
- SqlCacheDependencySection.cs
- DependencyPropertyHelper.cs
- ElementsClipboardData.cs
- _CacheStreams.cs
- EventHandlerList.cs
- KnownTypesHelper.cs
- StylusPlugInCollection.cs
- MetadataArtifactLoaderCompositeFile.cs
- SocketException.cs
- RedistVersionInfo.cs
- ListControl.cs
- SystemGatewayIPAddressInformation.cs
- ViewKeyConstraint.cs
- PostBackOptions.cs
- Misc.cs
- PathGeometry.cs
- IList.cs
- DataBindingList.cs
- DBConcurrencyException.cs
- AmbiguousMatchException.cs
- FileSystemWatcher.cs
- XslAstAnalyzer.cs
- RequestTimeoutManager.cs
- SpecularMaterial.cs
- EventPrivateKey.cs
- VarRefManager.cs
- MappingModelBuildProvider.cs
- EventlogProvider.cs
- clipboard.cs
- DataGridViewButtonColumn.cs
- DelegateSerializationHolder.cs
- SyndicationPerson.cs
- DataGridViewRowsAddedEventArgs.cs
- RecordConverter.cs
- RowParagraph.cs
- Transaction.cs
- GroupAggregateExpr.cs
- DataGridParentRows.cs
- SessionEndingCancelEventArgs.cs
- IndexerNameAttribute.cs