Code:
/ 4.0 / 4.0 / 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. ///// 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
- DragDrop.cs
- WebConfigurationHostFileChange.cs
- Native.cs
- WaveHeader.cs
- SqlMetaData.cs
- WebPartHeaderCloseVerb.cs
- SystemColorTracker.cs
- ToolStripProgressBar.cs
- FlowSwitchDesigner.xaml.cs
- ListViewItem.cs
- DataGridViewControlCollection.cs
- XPathSelfQuery.cs
- ObjectListCommandCollection.cs
- RenamedEventArgs.cs
- TextViewSelectionProcessor.cs
- _ConnectOverlappedAsyncResult.cs
- DiscoveryMessageSequenceGenerator.cs
- TextTrailingWordEllipsis.cs
- SubpageParagraph.cs
- ByteStreamGeometryContext.cs
- ConfigurationSectionHelper.cs
- RootCodeDomSerializer.cs
- Tool.cs
- Certificate.cs
- ParentQuery.cs
- PolicyDesigner.cs
- IPGlobalProperties.cs
- XslTransform.cs
- XmlDictionaryReader.cs
- Bidi.cs
- XmlILModule.cs
- TreeIterator.cs
- FixUp.cs
- ListControlConvertEventArgs.cs
- SqlInfoMessageEvent.cs
- DerivedKeyCachingSecurityTokenSerializer.cs
- AttachedProperty.cs
- SiteMapNode.cs
- NetNamedPipeSecurityElement.cs
- CodeConditionStatement.cs
- SqlProviderUtilities.cs
- FlowDocumentFormatter.cs
- PointLightBase.cs
- FixedSOMContainer.cs
- TrackingLocationCollection.cs
- comcontractssection.cs
- BuildProvidersCompiler.cs
- TraceSection.cs
- DataServiceProviderWrapper.cs
- ColumnMapCopier.cs
- EntityCollection.cs
- ErrorWebPart.cs
- DataTemplateSelector.cs
- BypassElementCollection.cs
- EventHandlerList.cs
- DelegateSerializationHolder.cs
- StringStorage.cs
- BrowserDefinition.cs
- XmlElementElementCollection.cs
- RotateTransform3D.cs
- NullableDecimalSumAggregationOperator.cs
- ProgressBarHighlightConverter.cs
- _Win32.cs
- ActivityStatusChangeEventArgs.cs
- AccessViolationException.cs
- FunctionParameter.cs
- ToolStripItemEventArgs.cs
- ActionFrame.cs
- DBAsyncResult.cs
- TableRow.cs
- FixedTextContainer.cs
- TextServicesCompartment.cs
- Dynamic.cs
- TraceHandlerErrorFormatter.cs
- SafeRightsManagementEnvironmentHandle.cs
- XmlNamedNodeMap.cs
- SelectionGlyph.cs
- CombinedGeometry.cs
- WsatServiceAddress.cs
- SmtpCommands.cs
- ToolStripRenderer.cs
- SevenBitStream.cs
- AssignDesigner.xaml.cs
- TabControlEvent.cs
- dataSvcMapFileLoader.cs
- OptimizedTemplateContent.cs
- GiveFeedbackEventArgs.cs
- SamlDoNotCacheCondition.cs
- SplineKeyFrames.cs
- SqlXmlStorage.cs
- HandlerMappingMemo.cs
- GeneralTransform3D.cs
- DataGridView.cs
- SineEase.cs
- JapaneseCalendar.cs
- ShaperBuffers.cs
- SoapMessage.cs
- BitSet.cs
- DynamicDataRouteHandler.cs
- StringSource.cs