Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / 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); } } } } }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
- ExtensibleClassFactory.cs
- ZoneIdentityPermission.cs
- EventListenerClientSide.cs
- MsmqInputMessage.cs
- XsltFunctions.cs
- ConnectionPoint.cs
- DataGridViewRowCollection.cs
- GeneralTransform3DTo2D.cs
- UserControlParser.cs
- Vector.cs
- DetailsViewCommandEventArgs.cs
- XPathItem.cs
- DefaultTraceListener.cs
- XmlSchemaElement.cs
- TextBoxLine.cs
- ColumnWidthChangedEvent.cs
- WSTrust.cs
- OutputScopeManager.cs
- TextBlockAutomationPeer.cs
- SamlAdvice.cs
- OLEDB_Enum.cs
- HTTPRemotingHandler.cs
- Stylesheet.cs
- HtmlWindow.cs
- AnimationStorage.cs
- AppDomainAttributes.cs
- GC.cs
- COM2TypeInfoProcessor.cs
- HttpCacheParams.cs
- SoapTransportImporter.cs
- Vars.cs
- ColumnMapProcessor.cs
- IERequestCache.cs
- DataGridViewCellEventArgs.cs
- ArglessEventHandlerProxy.cs
- RepeatEnumerable.cs
- PreloadedPackages.cs
- AlternateViewCollection.cs
- HttpRuntime.cs
- Compilation.cs
- SQlBooleanStorage.cs
- DrawTreeNodeEventArgs.cs
- CheckedListBox.cs
- MobileContainerDesigner.cs
- SqlDesignerDataSourceView.cs
- LiteralControl.cs
- XmlNamespaceManager.cs
- SchemaTableOptionalColumn.cs
- figurelength.cs
- _FixedSizeReader.cs
- OleDbError.cs
- D3DImage.cs
- HttpProfileGroupBase.cs
- InternalControlCollection.cs
- DataStreams.cs
- InternalsVisibleToAttribute.cs
- SqlCommandSet.cs
- WebControl.cs
- InkCollectionBehavior.cs
- VSWCFServiceContractGenerator.cs
- FixedBufferAttribute.cs
- SystemResourceHost.cs
- EdmComplexTypeAttribute.cs
- ByteConverter.cs
- DependencySource.cs
- SmtpDigestAuthenticationModule.cs
- TypeSystem.cs
- Executor.cs
- DmlSqlGenerator.cs
- TypeConverterValueSerializer.cs
- XmlQueryStaticData.cs
- BooleanExpr.cs
- ArrangedElement.cs
- CorrelationService.cs
- DefaultValueTypeConverter.cs
- XmlQueryOutput.cs
- PackWebRequestFactory.cs
- CqlLexer.cs
- SchemaMerger.cs
- XsdDateTime.cs
- Activation.cs
- CommandDevice.cs
- MobileListItemCollection.cs
- ComponentChangingEvent.cs
- SHA1Managed.cs
- XmlException.cs
- OdbcInfoMessageEvent.cs
- SecurityHelper.cs
- Delegate.cs
- CanonicalFontFamilyReference.cs
- PropertyPath.cs
- DtrList.cs
- MappingMetadataHelper.cs
- EventProxy.cs
- RightsDocument.cs
- StringCollection.cs
- SeverityFilter.cs
- ZipIOExtraFieldZip64Element.cs
- LinqDataSourceDeleteEventArgs.cs
- DataGridViewRowConverter.cs