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
- RenderTargetBitmap.cs
- SortQuery.cs
- EncoderFallback.cs
- OrderedDictionary.cs
- SQLMoneyStorage.cs
- PathHelper.cs
- TypeElementCollection.cs
- Property.cs
- CustomBindingCollectionElement.cs
- ResourceLoader.cs
- TextPointer.cs
- ToolBarTray.cs
- BufferModesCollection.cs
- Table.cs
- XPathNodeInfoAtom.cs
- StylusSystemGestureEventArgs.cs
- BindingExpressionUncommonField.cs
- XsdBuilder.cs
- DecimalConstantAttribute.cs
- GridViewColumnCollection.cs
- Shape.cs
- ManipulationStartedEventArgs.cs
- ProviderUtil.cs
- messageonlyhwndwrapper.cs
- Marshal.cs
- GeometryGroup.cs
- Utility.cs
- MobileSysDescriptionAttribute.cs
- DirectoryNotFoundException.cs
- DelegateSerializationHolder.cs
- XmlComment.cs
- linebase.cs
- RichTextBoxDesigner.cs
- QilGeneratorEnv.cs
- Stack.cs
- AttributeUsageAttribute.cs
- RuntimeArgument.cs
- ClientCultureInfo.cs
- PenCursorManager.cs
- ProfilePropertyNameValidator.cs
- UInt64.cs
- DocumentCollection.cs
- DiagnosticTrace.cs
- FontFaceLayoutInfo.cs
- HybridDictionary.cs
- oledbmetadatacolumnnames.cs
- SqlWebEventProvider.cs
- Cursor.cs
- PathSegmentCollection.cs
- SizeAnimation.cs
- DetailsViewUpdatedEventArgs.cs
- ConfigXmlAttribute.cs
- InternalControlCollection.cs
- ImageUrlEditor.cs
- Pick.cs
- TextTreeNode.cs
- DataServiceRequestException.cs
- Query.cs
- DbException.cs
- DesignerTextBoxAdapter.cs
- SafeLocalAllocation.cs
- List.cs
- DeferrableContentConverter.cs
- StronglyTypedResourceBuilder.cs
- prefixendpointaddressmessagefiltertable.cs
- DesignerAttribute.cs
- ImageCodecInfo.cs
- ModelTreeEnumerator.cs
- BindingManagerDataErrorEventArgs.cs
- JsonStringDataContract.cs
- NullableDecimalSumAggregationOperator.cs
- XmlAttributeAttribute.cs
- SecurityPermission.cs
- PartialArray.cs
- TypeRestriction.cs
- ConstrainedDataObject.cs
- TraceContextEventArgs.cs
- ProfileSettingsCollection.cs
- WebPartMinimizeVerb.cs
- QilScopedVisitor.cs
- ValueQuery.cs
- PathSegment.cs
- NativeMethods.cs
- CharEntityEncoderFallback.cs
- CompositeControlDesigner.cs
- StringHandle.cs
- DataSvcMapFile.cs
- ExpressionWriter.cs
- _Rfc2616CacheValidators.cs
- IgnoreSection.cs
- StrokeNodeEnumerator.cs
- ListViewContainer.cs
- ContainerControl.cs
- SymLanguageVendor.cs
- ModelPerspective.cs
- PropertyMetadata.cs
- TransactionFlowAttribute.cs
- CompressEmulationStream.cs
- ScriptControlManager.cs
- SqlVisitor.cs