Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / CompMod / System / ComponentModel / TypeListConverter.cs / 1 / TypeListConverter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.ComponentModel { using Microsoft.Win32; using System.Collections; using System.ComponentModel.Design.Serialization; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Remoting; using System.Runtime.Serialization.Formatters; using System.Security.Permissions; ////// [HostProtection(SharedState = true)] public abstract class TypeListConverter : TypeConverter { private Type[] types; private StandardValuesCollection values; ///Provides a type /// converter that can be used to populate a list box with available types. ////// protected TypeListConverter(Type[] types) { this.types = types; } ///Initializes a new instance of the ///class using /// the type array as the available types. /// /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertFrom(context, sourceType); } ///Gets a value indicating whether this converter /// can convert an object in the given source type to an enumeration object using /// the specified context. ////// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) { return true; } return base.CanConvertTo(context, destinationType); } ///Gets a value indicating whether this converter can /// convert an object to the given destination type using the context. ////// /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { foreach(Type t in types) { if (value.Equals(t.FullName)) { return t; } } } return base.ConvertFrom(context, culture, value); } ///Converts the specified value object to an enumeration object. ////// /// 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 == null) { return SR.GetString(SR.toStringNone); } else { return((Type)value).FullName; } } if (destinationType == typeof(InstanceDescriptor) && value is Type) { MethodInfo method = typeof(Type).GetMethod("GetType", new Type[] {typeof(string)}); if (method != null) { return new InstanceDescriptor(method, new object[] {((Type)value).AssemblyQualifiedName}); } } return base.ConvertTo(context, culture, value, destinationType); } ///Converts the given value object to the specified destination type. ////// /// public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { if (values == null) { object[] objTypes; if (types != null) { objTypes = new object[types.Length]; Array.Copy(types, objTypes, types.Length); } else { objTypes = null; } values = new StandardValuesCollection(objTypes); } return values; } ///Gets a collection of standard values for the data type this validator is /// designed for. ////// /// public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } ///Gets a value indicating whether the list of standard values returned from /// ///is an exclusive list. /// /// public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //Gets a value indicating whether this object supports a /// standard set of values that can be picked from a list using the specified /// context. ///// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.ComponentModel { using Microsoft.Win32; using System.Collections; using System.ComponentModel.Design.Serialization; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Remoting; using System.Runtime.Serialization.Formatters; using System.Security.Permissions; ////// [HostProtection(SharedState = true)] public abstract class TypeListConverter : TypeConverter { private Type[] types; private StandardValuesCollection values; ///Provides a type /// converter that can be used to populate a list box with available types. ////// protected TypeListConverter(Type[] types) { this.types = types; } ///Initializes a new instance of the ///class using /// the type array as the available types. /// /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertFrom(context, sourceType); } ///Gets a value indicating whether this converter /// can convert an object in the given source type to an enumeration object using /// the specified context. ////// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) { return true; } return base.CanConvertTo(context, destinationType); } ///Gets a value indicating whether this converter can /// convert an object to the given destination type using the context. ////// /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { foreach(Type t in types) { if (value.Equals(t.FullName)) { return t; } } } return base.ConvertFrom(context, culture, value); } ///Converts the specified value object to an enumeration object. ////// /// 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 == null) { return SR.GetString(SR.toStringNone); } else { return((Type)value).FullName; } } if (destinationType == typeof(InstanceDescriptor) && value is Type) { MethodInfo method = typeof(Type).GetMethod("GetType", new Type[] {typeof(string)}); if (method != null) { return new InstanceDescriptor(method, new object[] {((Type)value).AssemblyQualifiedName}); } } return base.ConvertTo(context, culture, value, destinationType); } ///Converts the given value object to the specified destination type. ////// /// public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { if (values == null) { object[] objTypes; if (types != null) { objTypes = new object[types.Length]; Array.Copy(types, objTypes, types.Length); } else { objTypes = null; } values = new StandardValuesCollection(objTypes); } return values; } ///Gets a collection of standard values for the data type this validator is /// designed for. ////// /// public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } ///Gets a value indicating whether the list of standard values returned from /// ///is an exclusive list. /// /// public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.Gets a value indicating whether this object supports a /// standard set of values that can be picked from a list using the specified /// context. ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PingReply.cs
- VectorCollection.cs
- Comparer.cs
- ObjectDataSourceFilteringEventArgs.cs
- WizardStepCollectionEditor.cs
- LineServicesRun.cs
- HMACSHA384.cs
- HMACRIPEMD160.cs
- Int16KeyFrameCollection.cs
- EnumerableRowCollection.cs
- GeneralTransform2DTo3DTo2D.cs
- ResourcesBuildProvider.cs
- SHA256Managed.cs
- DataBoundControlHelper.cs
- FunctionNode.cs
- Compiler.cs
- InvokeProviderWrapper.cs
- PlaceHolder.cs
- webeventbuffer.cs
- TdsParserStateObject.cs
- MembershipAdapter.cs
- TrustSection.cs
- ListDictionary.cs
- PropertyTab.cs
- QilLiteral.cs
- GridViewSelectEventArgs.cs
- Vertex.cs
- VirtualizingPanel.cs
- DocumentPaginator.cs
- DynamicFilterExpression.cs
- PointAnimationBase.cs
- StretchValidation.cs
- ListViewItem.cs
- PackageRelationshipSelector.cs
- MULTI_QI.cs
- ExtentCqlBlock.cs
- CompositeDataBoundControl.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- ProfileManager.cs
- GCHandleCookieTable.cs
- TextBox.cs
- AssemblyResourceLoader.cs
- Baml2006KeyRecord.cs
- ConfigXmlText.cs
- XpsStructure.cs
- AvtEvent.cs
- OdbcFactory.cs
- ReflectionUtil.cs
- XmlCharacterData.cs
- FontCacheLogic.cs
- ParallelTimeline.cs
- CodeTypeDeclarationCollection.cs
- MatrixCamera.cs
- UDPClient.cs
- CreateUserWizard.cs
- XmlReaderSettings.cs
- ConstraintConverter.cs
- ISCIIEncoding.cs
- SqlInternalConnectionTds.cs
- TextSpanModifier.cs
- ISSmlParser.cs
- Baml2006Reader.cs
- _NegotiateClient.cs
- IdentityReference.cs
- ByteAnimation.cs
- CodeAccessSecurityEngine.cs
- XmlStreamStore.cs
- BooleanProjectedSlot.cs
- ClrPerspective.cs
- SectionRecord.cs
- ManagedIStream.cs
- SqlCacheDependencyDatabase.cs
- Ray3DHitTestResult.cs
- TypeConverterHelper.cs
- OracleBFile.cs
- ExpandSegment.cs
- FixedPageAutomationPeer.cs
- IImplicitResourceProvider.cs
- Common.cs
- WebPartConnectionsEventArgs.cs
- HelpProvider.cs
- DetailsViewCommandEventArgs.cs
- _Rfc2616CacheValidators.cs
- RowToFieldTransformer.cs
- TypeUtil.cs
- DBDataPermissionAttribute.cs
- SecurityElementBase.cs
- Hex.cs
- CompressionTransform.cs
- embossbitmapeffect.cs
- SpellerHighlightLayer.cs
- TrackingStringDictionary.cs
- MobileResource.cs
- GlyphsSerializer.cs
- HScrollBar.cs
- Boolean.cs
- autovalidator.cs
- FormsAuthenticationUser.cs
- RadioButtonAutomationPeer.cs
- FileFormatException.cs