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
- CodeMethodReturnStatement.cs
- EndpointDiscoveryElement.cs
- FontCollection.cs
- SecurityContext.cs
- WebPartEditorOkVerb.cs
- SamlAuthorityBinding.cs
- BaseTemplateBuildProvider.cs
- GeneralTransform3D.cs
- HtmlEncodedRawTextWriter.cs
- RayMeshGeometry3DHitTestResult.cs
- DataPagerFieldItem.cs
- Vector3DIndependentAnimationStorage.cs
- CustomAttributeSerializer.cs
- DesignTimeParseData.cs
- AnnotationHighlightLayer.cs
- PatternMatcher.cs
- LineServicesRun.cs
- ActivitySurrogate.cs
- Events.cs
- TableItemPatternIdentifiers.cs
- SQLResource.cs
- AuthenticationService.cs
- TextTreeExtractElementUndoUnit.cs
- FileRecordSequence.cs
- ImmutableObjectAttribute.cs
- Point4DValueSerializer.cs
- StylusPointPropertyInfo.cs
- SignedPkcs7.cs
- Axis.cs
- KeyValueConfigurationCollection.cs
- CFGGrammar.cs
- ViewPort3D.cs
- DataListItem.cs
- Classification.cs
- DecimalAverageAggregationOperator.cs
- PathSegment.cs
- XmlMapping.cs
- DashStyle.cs
- IPEndPointCollection.cs
- IRCollection.cs
- ByteAnimationUsingKeyFrames.cs
- PolyLineSegmentFigureLogic.cs
- FrameworkContentElement.cs
- TypeConverterHelper.cs
- InvariantComparer.cs
- SamlNameIdentifierClaimResource.cs
- MetadataItem_Static.cs
- SessionEndingEventArgs.cs
- DataGridViewColumnCollection.cs
- SyndicationSerializer.cs
- DataSourceControl.cs
- Cursor.cs
- ExpressionList.cs
- RequiredFieldValidator.cs
- ToolStripButton.cs
- PrintingPermissionAttribute.cs
- DesignerTextWriter.cs
- BrushConverter.cs
- _LazyAsyncResult.cs
- SQLBinary.cs
- Script.cs
- PersistChildrenAttribute.cs
- HttpInputStream.cs
- XmlMtomReader.cs
- ToolStripHighContrastRenderer.cs
- LayoutEngine.cs
- XmlILStorageConverter.cs
- RecognizerStateChangedEventArgs.cs
- CharacterHit.cs
- X509WindowsSecurityToken.cs
- WinFormsComponentEditor.cs
- TableParagraph.cs
- WeakReferenceKey.cs
- ObjectSet.cs
- StylusCollection.cs
- ArgumentNullException.cs
- InstanceData.cs
- CodeSnippetTypeMember.cs
- CustomAttributeFormatException.cs
- WinCategoryAttribute.cs
- Attributes.cs
- DataServiceCollectionOfT.cs
- DetailsViewInsertedEventArgs.cs
- FirewallWrapper.cs
- Semaphore.cs
- EntityException.cs
- XmlDocumentSchema.cs
- PersonalizationStateQuery.cs
- StylusPlugin.cs
- WebConfigurationManager.cs
- CodeArrayCreateExpression.cs
- WebPartVerbCollection.cs
- ProxyAttribute.cs
- WindowsGraphicsWrapper.cs
- HtmlInputSubmit.cs
- ToolStripItemDataObject.cs
- XmlWriter.cs
- BrowserCapabilitiesCodeGenerator.cs
- ReadOnlyNameValueCollection.cs
- NotFiniteNumberException.cs