Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- XmlSchemaObjectCollection.cs
- ThicknessAnimation.cs
- RequestQueue.cs
- RIPEMD160.cs
- MetadataArtifactLoaderCompositeResource.cs
- EntityDataSourceWizardForm.cs
- Assembly.cs
- IntPtr.cs
- TripleDESCryptoServiceProvider.cs
- XhtmlMobileTextWriter.cs
- CanonicalFormWriter.cs
- EmptyElement.cs
- StackBuilderSink.cs
- DebugView.cs
- DisplayInformation.cs
- ProgressiveCrcCalculatingStream.cs
- DataGridViewColumnTypePicker.cs
- HttpListenerException.cs
- CustomExpression.cs
- SqlInternalConnection.cs
- QilStrConcatenator.cs
- TokenizerHelper.cs
- HttpListenerResponse.cs
- Inflater.cs
- ReadOnlyDataSourceView.cs
- InfoCardService.cs
- ExtractedStateEntry.cs
- SystemIPInterfaceStatistics.cs
- Repeater.cs
- JsonReaderDelegator.cs
- DataGridLength.cs
- ListViewPagedDataSource.cs
- SecUtil.cs
- RealizedColumnsBlock.cs
- HttpFileCollection.cs
- XmlSerializerAssemblyAttribute.cs
- DefaultTextStore.cs
- TableAdapterManagerMethodGenerator.cs
- ListSortDescriptionCollection.cs
- SqlInfoMessageEvent.cs
- MissingSatelliteAssemblyException.cs
- GenerateTemporaryTargetAssembly.cs
- TemplateContainer.cs
- Processor.cs
- ZipIOLocalFileBlock.cs
- CmsInterop.cs
- CompilerError.cs
- Environment.cs
- HwndStylusInputProvider.cs
- iisPickupDirectory.cs
- NamedPermissionSet.cs
- PropertyInfoSet.cs
- ClassDataContract.cs
- SecurityProtocolCorrelationState.cs
- ProviderUtil.cs
- DesignerDataParameter.cs
- ValidatingPropertiesEventArgs.cs
- EncoderExceptionFallback.cs
- XmlQualifiedNameTest.cs
- DbCommandTree.cs
- MetadataItemEmitter.cs
- StorageEndPropertyMapping.cs
- JsonDataContract.cs
- VirtualPath.cs
- ComponentResourceKeyConverter.cs
- SolidColorBrush.cs
- TextLine.cs
- SqlDataSourceCommandEventArgs.cs
- ProfileService.cs
- StorageRoot.cs
- Win32KeyboardDevice.cs
- PageContentAsyncResult.cs
- AssociationTypeEmitter.cs
- ToggleButtonAutomationPeer.cs
- ObjectAnimationUsingKeyFrames.cs
- OracleColumn.cs
- FormatConvertedBitmap.cs
- TableColumn.cs
- ColumnProvider.cs
- DriveInfo.cs
- IdnMapping.cs
- SqlNodeAnnotations.cs
- DataSpaceManager.cs
- ContextMenuService.cs
- InterleavedZipPartStream.cs
- FontEmbeddingManager.cs
- TypeInfo.cs
- TransformerInfo.cs
- DescendantOverDescendantQuery.cs
- ControlParameter.cs
- WebPartConnectionCollection.cs
- ReflectPropertyDescriptor.cs
- MemberCollection.cs
- ConfigXmlReader.cs
- ScriptingJsonSerializationSection.cs
- LogicalExpr.cs
- BorderGapMaskConverter.cs
- Rotation3D.cs
- HtmlInputFile.cs
- VisualStyleElement.cs