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
- AlgoModule.cs
- CopyNodeSetAction.cs
- WebSysDefaultValueAttribute.cs
- DeflateStream.cs
- UIElementHelper.cs
- UdpTransportBindingElement.cs
- InlineObject.cs
- XhtmlCssHandler.cs
- RemotingServices.cs
- ForceCopyBuildProvider.cs
- ModulesEntry.cs
- CodeMemberEvent.cs
- WebPartEditorCancelVerb.cs
- ReturnValue.cs
- ModelPerspective.cs
- IssuedSecurityTokenProvider.cs
- AppSecurityManager.cs
- MediaPlayer.cs
- CodeDomExtensionMethods.cs
- ViewStateModeByIdAttribute.cs
- dataobject.cs
- DocumentPaginator.cs
- IntMinMaxAggregationOperator.cs
- ExtendedPropertiesHandler.cs
- VoiceChangeEventArgs.cs
- ExpanderAutomationPeer.cs
- XmlBaseReader.cs
- ValidatedControlConverter.cs
- ProcessInputEventArgs.cs
- NamedElement.cs
- FontStyles.cs
- CompensationToken.cs
- BlobPersonalizationState.cs
- EventSetter.cs
- ContentType.cs
- WebServiceReceive.cs
- MemberJoinTreeNode.cs
- ResourceManagerWrapper.cs
- NamespaceCollection.cs
- StructuredTypeEmitter.cs
- UiaCoreTypesApi.cs
- BCLDebug.cs
- DataSourceDesigner.cs
- WorkflowDurableInstance.cs
- DownloadProgressEventArgs.cs
- WebServiceReceiveDesigner.cs
- DataBinding.cs
- RadialGradientBrush.cs
- ImageDrawing.cs
- __ConsoleStream.cs
- TableSectionStyle.cs
- DataGridViewCellFormattingEventArgs.cs
- WebPartsPersonalizationAuthorization.cs
- FlowLayoutSettings.cs
- IndividualDeviceConfig.cs
- GroupStyle.cs
- ClockGroup.cs
- TableRow.cs
- ScrollChangedEventArgs.cs
- XslNumber.cs
- WebHttpSecurityElement.cs
- ConnectorMovedEventArgs.cs
- DetailsViewPageEventArgs.cs
- MonikerBuilder.cs
- XmlSignatureManifest.cs
- DynamicILGenerator.cs
- Vector3DCollection.cs
- EntityConnectionStringBuilder.cs
- StructureChangedEventArgs.cs
- HtmlInputFile.cs
- PropertyFilterAttribute.cs
- SafeFileMappingHandle.cs
- MultiTouchSystemGestureLogic.cs
- InternalConfigSettingsFactory.cs
- HuffModule.cs
- cookiecollection.cs
- TemplateInstanceAttribute.cs
- OnOperation.cs
- Match.cs
- LineServicesCallbacks.cs
- SettingsPropertyIsReadOnlyException.cs
- Deserializer.cs
- XmlTextAttribute.cs
- SelectionProviderWrapper.cs
- DbReferenceCollection.cs
- UserPersonalizationStateInfo.cs
- DocumentPaginator.cs
- Size3DConverter.cs
- odbcmetadatafactory.cs
- HttpCachePolicyElement.cs
- CodeSubDirectoriesCollection.cs
- ISAPIRuntime.cs
- TypeInformation.cs
- HashCryptoHandle.cs
- TrustManagerPromptUI.cs
- FreezableCollection.cs
- PersianCalendar.cs
- Timer.cs
- OutputCacheProfile.cs
- WebRequestModuleElement.cs