Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- DoubleLinkListEnumerator.cs
- ResourcesChangeInfo.cs
- TypeContext.cs
- PointConverter.cs
- SQLGuid.cs
- ApplicationTrust.cs
- TextRange.cs
- VisualStyleInformation.cs
- SatelliteContractVersionAttribute.cs
- GenericTypeParameterBuilder.cs
- ConfigXmlReader.cs
- ScriptControlManager.cs
- BoundPropertyEntry.cs
- SimpleHandlerBuildProvider.cs
- HttpListenerException.cs
- BooleanExpr.cs
- ClusterRegistryConfigurationProvider.cs
- ComponentResourceKey.cs
- CapabilitiesSection.cs
- WorkerRequest.cs
- SignedXml.cs
- WindowsContainer.cs
- ControlValuePropertyAttribute.cs
- ObjectParameter.cs
- X509Certificate.cs
- RegisteredArrayDeclaration.cs
- InkCanvasAutomationPeer.cs
- Queue.cs
- PropertyItem.cs
- JsonQNameDataContract.cs
- MethodBuilderInstantiation.cs
- CheckBoxField.cs
- TemplatePartAttribute.cs
- HwndProxyElementProvider.cs
- SerializableAttribute.cs
- StringWriter.cs
- MimeMapping.cs
- DesignTable.cs
- CustomErrorsSectionWrapper.cs
- SmtpNegotiateAuthenticationModule.cs
- DesignerActionKeyboardBehavior.cs
- ProfileSettingsCollection.cs
- DeflateEmulationStream.cs
- HierarchicalDataSourceIDConverter.cs
- ProvidersHelper.cs
- ScalarConstant.cs
- Rijndael.cs
- TdsRecordBufferSetter.cs
- RegexStringValidatorAttribute.cs
- EditorZone.cs
- SerializationObjectManager.cs
- PersonalizablePropertyEntry.cs
- BuildDependencySet.cs
- Expression.cs
- DataBindingList.cs
- DbConnectionPoolGroup.cs
- StylusEditingBehavior.cs
- ItemsControlAutomationPeer.cs
- XamlStackWriter.cs
- GacUtil.cs
- SafeRegistryHandle.cs
- WinCategoryAttribute.cs
- StorageMappingItemLoader.cs
- ReflectionTypeLoadException.cs
- SynchronizedDispatch.cs
- listitem.cs
- _CookieModule.cs
- PopupEventArgs.cs
- TemplateBindingExtension.cs
- QueryPageSettingsEventArgs.cs
- DataControlFieldCollection.cs
- DataKeyCollection.cs
- PropertyTabChangedEvent.cs
- FontFamily.cs
- OdbcParameter.cs
- Command.cs
- WebConfigurationHostFileChange.cs
- FormsAuthenticationUser.cs
- RotateTransform3D.cs
- BindableAttribute.cs
- SQLInt64Storage.cs
- ToolStripHighContrastRenderer.cs
- DiagnosticTrace.cs
- AssociationSetMetadata.cs
- OpenFileDialog.cs
- RemotingServices.cs
- SqlWriter.cs
- ProtocolElement.cs
- LogManagementAsyncResult.cs
- FocusWithinProperty.cs
- Polyline.cs
- CodeDomConfigurationHandler.cs
- TextRangeEditTables.cs
- SHA384.cs
- WorkflowFileItem.cs
- BuildDependencySet.cs
- DispatchChannelSink.cs
- RemotingConfiguration.cs
- FlowThrottle.cs
- ListItemCollection.cs