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
- CommandPlan.cs
- ObjectComplexPropertyMapping.cs
- TypeRefElement.cs
- RTTypeWrapper.cs
- PaginationProgressEventArgs.cs
- _UncName.cs
- NotificationContext.cs
- RawKeyboardInputReport.cs
- ComponentResourceKey.cs
- LayoutManager.cs
- Timeline.cs
- Image.cs
- MatrixCamera.cs
- WindowsEditBoxRange.cs
- Queue.cs
- CodeTypeMember.cs
- JoinTreeNode.cs
- MenuAdapter.cs
- DesignerActionUI.cs
- Util.cs
- SafeBitVector32.cs
- ServiceMetadataExtension.cs
- Normalization.cs
- CharStorage.cs
- SmtpDigestAuthenticationModule.cs
- Comparer.cs
- CollectionBase.cs
- ClientApiGenerator.cs
- StickyNoteAnnotations.cs
- CodeDomComponentSerializationService.cs
- ByteStreamMessageUtility.cs
- NativeMethodsOther.cs
- EntityConnectionStringBuilder.cs
- DetailsViewCommandEventArgs.cs
- ResumeStoryboard.cs
- DataGridCommandEventArgs.cs
- UnicastIPAddressInformationCollection.cs
- TextServicesProperty.cs
- DynamicRendererThreadManager.cs
- StreamSecurityUpgradeInitiatorBase.cs
- EntityContainerEmitter.cs
- LineProperties.cs
- ProcessThread.cs
- CapacityStreamGeometryContext.cs
- CLRBindingWorker.cs
- AxisAngleRotation3D.cs
- PkcsMisc.cs
- EpmContentSerializer.cs
- TemplateDefinition.cs
- DataRecordObjectView.cs
- RunInstallerAttribute.cs
- MessageQueueException.cs
- WinFormsSecurity.cs
- TrustLevelCollection.cs
- PropertyPathConverter.cs
- ToolBarTray.cs
- DefaultValidator.cs
- AuthenticationServiceManager.cs
- Msec.cs
- ResXDataNode.cs
- AppSettingsSection.cs
- EntityDataSourceReferenceGroup.cs
- serverconfig.cs
- MemberInitExpression.cs
- RtType.cs
- Relationship.cs
- TemplateColumn.cs
- SystemIPv6InterfaceProperties.cs
- XamlWriter.cs
- CommandHelpers.cs
- DesignerLabelAdapter.cs
- SafeCoTaskMem.cs
- BindingList.cs
- TypeConverter.cs
- BinaryFormatter.cs
- DynamicResourceExtension.cs
- DashStyle.cs
- FlowDecisionDesigner.xaml.cs
- CustomAttributeSerializer.cs
- IApplicationTrustManager.cs
- TextDecorationCollectionConverter.cs
- HttpCachePolicy.cs
- DataMember.cs
- DocumentPageView.cs
- WebUtil.cs
- PenCursorManager.cs
- RSAPKCS1SignatureFormatter.cs
- NamedPermissionSet.cs
- CodeArrayCreateExpression.cs
- ManualResetEvent.cs
- DayRenderEvent.cs
- TreeNodeMouseHoverEvent.cs
- DebugController.cs
- BindingList.cs
- SecurityState.cs
- RowBinding.cs
- AutomationAttributeInfo.cs
- XmlNamespaceDeclarationsAttribute.cs
- Size3D.cs
- SqlFunctionAttribute.cs