Code:
/ 4.0 / 4.0 / untmp / 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. ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Internal.cs
- NodeInfo.cs
- ListDesigner.cs
- CalendarAutoFormatDialog.cs
- TabControl.cs
- XmlAnyElementAttributes.cs
- XamlPointCollectionSerializer.cs
- ContractBase.cs
- AsymmetricSignatureFormatter.cs
- XmlBindingWorker.cs
- SolidColorBrush.cs
- Pen.cs
- GC.cs
- HttpRuntime.cs
- RuntimeUtils.cs
- RegistryConfigurationProvider.cs
- StateManager.cs
- MailHeaderInfo.cs
- DataGridViewColumnEventArgs.cs
- GridItem.cs
- SystemGatewayIPAddressInformation.cs
- MsmqIntegrationInputChannel.cs
- PassportPrincipal.cs
- ObjectSecurity.cs
- TagPrefixAttribute.cs
- RemotingService.cs
- Reference.cs
- SafeArrayRankMismatchException.cs
- ConfigurationSectionGroup.cs
- TextShapeableCharacters.cs
- SecurityHeaderElementInferenceEngine.cs
- TimeSpan.cs
- ListControl.cs
- ResourceContainer.cs
- XmlSchemaSimpleContent.cs
- AttributeAction.cs
- XsdBuildProvider.cs
- WebPartConnectionCollection.cs
- Attributes.cs
- ActiveDocumentEvent.cs
- DiscoveryClientChannelBase.cs
- IpcChannel.cs
- ResourceDictionary.cs
- InfoCardRSAPKCS1KeyExchangeDeformatter.cs
- WebPartVerbCollection.cs
- DefaultObjectSerializer.cs
- DataTableReaderListener.cs
- ParameterEditorUserControl.cs
- SchemaImporterExtension.cs
- Simplifier.cs
- XPathScanner.cs
- XmlBufferReader.cs
- AddInContractAttribute.cs
- MD5HashHelper.cs
- WCFServiceClientProxyGenerator.cs
- AdCreatedEventArgs.cs
- CompleteWizardStep.cs
- DataSourceSelectArguments.cs
- ActiveDocumentEvent.cs
- Rules.cs
- UnsafeNativeMethods.cs
- AppDomainProtocolHandler.cs
- PeekCompletedEventArgs.cs
- pingexception.cs
- JsonServiceDocumentSerializer.cs
- HwndSubclass.cs
- TemplateControlCodeDomTreeGenerator.cs
- UseLicense.cs
- TraceLog.cs
- FunctionQuery.cs
- DBParameter.cs
- ConnectionPoint.cs
- StrokeCollectionConverter.cs
- ThrowOnMultipleAssignment.cs
- ObjectConverter.cs
- SessionStateModule.cs
- RightsManagementPermission.cs
- SettingsPropertyWrongTypeException.cs
- SHA256.cs
- WebPartCloseVerb.cs
- filewebrequest.cs
- WebPartVerbCollection.cs
- Page.cs
- Setter.cs
- BulletDecorator.cs
- ClaimTypeElementCollection.cs
- EditorZoneBase.cs
- DecoderBestFitFallback.cs
- InputReport.cs
- SqlDataSourceQueryConverter.cs
- Vector.cs
- CriticalExceptions.cs
- SchemaConstraints.cs
- BitFlagsGenerator.cs
- ParallelQuery.cs
- SchemaHelper.cs
- XmlUnspecifiedAttribute.cs
- RenderDataDrawingContext.cs
- ConstraintCollection.cs
- SafeFileMappingHandle.cs