Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CompMod / System / ComponentModel / ArrayConverter.cs / 1305376 / 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
- SevenBitStream.cs
- AvTraceDetails.cs
- RequestTimeoutManager.cs
- Cursors.cs
- AnnotationMap.cs
- ObjectIDGenerator.cs
- ServiceDebugElement.cs
- ChannelServices.cs
- Compilation.cs
- ScriptModule.cs
- MasterPageCodeDomTreeGenerator.cs
- TrackBarDesigner.cs
- RegexGroupCollection.cs
- StateRuntime.cs
- SymmetricCryptoHandle.cs
- XmlSchemaAnnotated.cs
- ColorInterpolationModeValidation.cs
- XmlEncodedRawTextWriter.cs
- PropertyEmitter.cs
- Win32.cs
- PolicyException.cs
- SQLMoneyStorage.cs
- ButtonColumn.cs
- CellParaClient.cs
- VirtualPathUtility.cs
- IISUnsafeMethods.cs
- WebPartTracker.cs
- WriterOutput.cs
- MimeObjectFactory.cs
- HitTestFilterBehavior.cs
- SimpleTextLine.cs
- XmlExceptionHelper.cs
- ReaderContextStackData.cs
- ApplyHostConfigurationBehavior.cs
- WindowsPrincipal.cs
- FileReader.cs
- FontResourceCache.cs
- SR.cs
- codemethodreferenceexpression.cs
- BuildManager.cs
- SystemUdpStatistics.cs
- SqlClientWrapperSmiStreamChars.cs
- QueryCacheEntry.cs
- HandlerFactoryCache.cs
- CompilerTypeWithParams.cs
- CapabilitiesPattern.cs
- XmlSerializerAssemblyAttribute.cs
- XmlCDATASection.cs
- DataGridColumnHeaderAutomationPeer.cs
- PersianCalendar.cs
- QueryContinueDragEventArgs.cs
- _NestedSingleAsyncResult.cs
- _SslState.cs
- SoapInteropTypes.cs
- AddInToken.cs
- EditorPartCollection.cs
- ErrorRuntimeConfig.cs
- ExtractedStateEntry.cs
- HashHelper.cs
- FrameworkPropertyMetadata.cs
- RNGCryptoServiceProvider.cs
- DataServiceConfiguration.cs
- SqlError.cs
- Vector3DAnimationUsingKeyFrames.cs
- NetSectionGroup.cs
- ResourceManager.cs
- XmlDictionary.cs
- Schema.cs
- SeekableReadStream.cs
- FastPropertyAccessor.cs
- ListControlBoundActionList.cs
- ColorInterpolationModeValidation.cs
- CompilationSection.cs
- IssuedTokenClientCredential.cs
- TreeWalker.cs
- XmlTextReaderImpl.cs
- NullReferenceException.cs
- TokenCreationException.cs
- FileUpload.cs
- QueryOperatorEnumerator.cs
- XsdCachingReader.cs
- WindowsIdentity.cs
- DataGridBeginningEditEventArgs.cs
- XmlSchemaSimpleContentRestriction.cs
- _NetRes.cs
- DbQueryCommandTree.cs
- EdmComplexTypeAttribute.cs
- WithParamAction.cs
- XmlName.cs
- DropShadowBitmapEffect.cs
- TextServicesHost.cs
- RouteValueExpressionBuilder.cs
- HttpCookiesSection.cs
- ObjectCacheHost.cs
- TextSpanModifier.cs
- ContractInstanceProvider.cs
- PointLightBase.cs
- ViewUtilities.cs
- GridItem.cs
- Parser.cs