Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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); } } } } } // 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
- XmlQueryType.cs
- ColumnHeaderCollectionEditor.cs
- ObjectKeyFrameCollection.cs
- DrawingVisual.cs
- NumberAction.cs
- RuntimeConfig.cs
- Vector3DConverter.cs
- FlowDocumentReaderAutomationPeer.cs
- SubstitutionResponseElement.cs
- WebPartEditorOkVerb.cs
- FixedSOMSemanticBox.cs
- FileLoadException.cs
- DoubleStorage.cs
- Flowchart.cs
- EpmContentDeSerializerBase.cs
- PictureBox.cs
- PreloadedPackages.cs
- AutomationPatternInfo.cs
- CharacterBuffer.cs
- LongValidator.cs
- FormViewInsertEventArgs.cs
- DetailsViewCommandEventArgs.cs
- TabPanel.cs
- PipeException.cs
- ControlCollection.cs
- FilteredXmlReader.cs
- DataGridAutomationPeer.cs
- Int64Converter.cs
- XmlReaderSettings.cs
- HtmlMeta.cs
- LinearQuaternionKeyFrame.cs
- CodeSnippetCompileUnit.cs
- CodeCatchClauseCollection.cs
- EventBindingService.cs
- ObjectAnimationBase.cs
- CatalogZone.cs
- SqlDataSourceView.cs
- SerializationFieldInfo.cs
- Decorator.cs
- ActivityXamlServices.cs
- ValidationSummary.cs
- XmlEnumAttribute.cs
- ValidatingPropertiesEventArgs.cs
- DataTableReader.cs
- CoTaskMemHandle.cs
- AssemblyFilter.cs
- PageFunction.cs
- BrowserDefinition.cs
- SqlWebEventProvider.cs
- PictureBox.cs
- DeviceContext.cs
- ApplicationInfo.cs
- ViewGenerator.cs
- XsdDataContractExporter.cs
- GridSplitter.cs
- ReferentialConstraintRoleElement.cs
- MissingManifestResourceException.cs
- ProviderUtil.cs
- XmlSchemaDocumentation.cs
- WindowsContainer.cs
- ExpressionTable.cs
- _ContextAwareResult.cs
- Line.cs
- OrderedDictionaryStateHelper.cs
- StorageMappingItemLoader.cs
- DataGridViewDataConnection.cs
- BaseResourcesBuildProvider.cs
- DataControlPagerLinkButton.cs
- HandleValueEditor.cs
- D3DImage.cs
- XmlEventCache.cs
- DataTableTypeConverter.cs
- JsonReaderDelegator.cs
- ApplicationManager.cs
- DataView.cs
- ClientSponsor.cs
- ConfigurationValues.cs
- MetadataSource.cs
- ShutDownListener.cs
- WebHttpSecurityElement.cs
- WebPartConnectionsConnectVerb.cs
- Stack.cs
- UInt16Storage.cs
- ToolBarTray.cs
- CompressedStack.cs
- RuntimeIdentifierPropertyAttribute.cs
- AddInStore.cs
- DoubleAnimationClockResource.cs
- IISMapPath.cs
- LineServicesCallbacks.cs
- ObjectViewEntityCollectionData.cs
- Model3DGroup.cs
- DataGridItemCollection.cs
- ApplicationManager.cs
- DataGridViewBand.cs
- Int16Storage.cs
- ToolStripDropDown.cs
- ConnectionManager.cs
- XmlEntityReference.cs
- MetadataSource.cs