Code:
/ FX-1434 / FX-1434 / 1.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
- dataprotectionpermissionattribute.cs
- TableCell.cs
- ExecutionEngineException.cs
- HttpCacheVaryByContentEncodings.cs
- LogEntrySerializationException.cs
- AccessDataSource.cs
- DecoderBestFitFallback.cs
- InstanceData.cs
- GeneratedCodeAttribute.cs
- PreviewPageInfo.cs
- M3DUtil.cs
- PasswordBoxAutomationPeer.cs
- PointAnimationBase.cs
- AliasedSlot.cs
- ContainerSelectorActiveEvent.cs
- SQLBinaryStorage.cs
- DesignerForm.cs
- ObjectDataSourceSelectingEventArgs.cs
- StaticDataManager.cs
- SemanticResolver.cs
- SmtpAuthenticationManager.cs
- SQLRoleProvider.cs
- NonPrimarySelectionGlyph.cs
- DoubleStorage.cs
- xsdvalidator.cs
- ColorAnimationUsingKeyFrames.cs
- ConnectionConsumerAttribute.cs
- WebPartConnectionsEventArgs.cs
- DispatcherFrame.cs
- DataGridItemEventArgs.cs
- XmlNamespaceMapping.cs
- DiscoveryDocumentSerializer.cs
- SafeArrayTypeMismatchException.cs
- WaitHandleCannotBeOpenedException.cs
- ReadOnlyPropertyMetadata.cs
- ThemeDirectoryCompiler.cs
- CharacterBuffer.cs
- XMLDiffLoader.cs
- Menu.cs
- StrongNameMembershipCondition.cs
- StrokeIntersection.cs
- ResponseStream.cs
- OleServicesContext.cs
- WindowsSecurityToken.cs
- ReadOnlyDataSourceView.cs
- CodeVariableReferenceExpression.cs
- ElementMarkupObject.cs
- ListParagraph.cs
- DataSourceControl.cs
- WebPartConnectionsCloseVerb.cs
- DragAssistanceManager.cs
- TCPListener.cs
- __Filters.cs
- ObjectHelper.cs
- DiscoveryOperationContext.cs
- Partitioner.cs
- TraceListener.cs
- DataServiceRequest.cs
- ColumnMapCopier.cs
- MarshalByRefObject.cs
- DataGridrowEditEndingEventArgs.cs
- ContentPlaceHolderDesigner.cs
- ConfigurationSectionCollection.cs
- OutputCacheSection.cs
- ClassGenerator.cs
- UndoEngine.cs
- XmlBinaryReader.cs
- PointAnimationClockResource.cs
- MatrixCamera.cs
- OracleBoolean.cs
- RelationshipSet.cs
- CqlGenerator.cs
- HyperLinkDataBindingHandler.cs
- DecimalConverter.cs
- Calendar.cs
- SQLChars.cs
- IntranetCredentialPolicy.cs
- ExtensionDataObject.cs
- HtmlControl.cs
- TransformCollection.cs
- Viewport3DAutomationPeer.cs
- DataBoundControlParameterTarget.cs
- ColumnCollectionEditor.cs
- ReturnType.cs
- Validator.cs
- ToolStripPanelRenderEventArgs.cs
- QueryRewriter.cs
- UniqueIdentifierService.cs
- WsatStrings.cs
- Icon.cs
- IEnumerable.cs
- ModelProperty.cs
- ListViewItemEventArgs.cs
- TypeRestriction.cs
- SHA384Managed.cs
- OutputCacheModule.cs
- UserPreferenceChangedEventArgs.cs
- HandledMouseEvent.cs
- ObjectDataSourceSelectingEventArgs.cs
- ResourcePool.cs