Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / 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;
///
/// Provides a type
/// converter that can be used to populate a list box with available types.
///
[HostProtection(SharedState = true)]
public abstract class TypeListConverter : TypeConverter {
private Type[] types;
private StandardValuesCollection values;
///
/// Initializes a new instance of the class using
/// the type array as the available types.
///
protected TypeListConverter(Type[] types) {
this.types = types;
}
///
///
/// 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 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 to the given destination type using the context.
///
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
if (destinationType == typeof(InstanceDescriptor)) {
return true;
}
return base.CanConvertTo(context, destinationType);
}
///
///
/// Converts the specified value object to an enumeration object.
///
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 given value object to the specified destination type.
///
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);
}
///
///
/// Gets a collection of standard values for the data type this validator is
/// designed for.
///
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 value indicating whether the list of standard values returned from
/// is an exclusive list.
///
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) {
return true;
}
///
///
/// Gets a value indicating whether this object supports a
/// standard set of values that can be picked from a list using the specified
/// context.
///
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
return true;
}
}
}
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RegionIterator.cs
- PassportAuthenticationEventArgs.cs
- DrawingAttributeSerializer.cs
- ExpressionHelper.cs
- HMACSHA512.cs
- SecurityManager.cs
- Transform.cs
- QuaternionValueSerializer.cs
- DesignerActionUIStateChangeEventArgs.cs
- ListViewGroup.cs
- OptimizerPatterns.cs
- ExtentCqlBlock.cs
- ProfileEventArgs.cs
- serverconfig.cs
- WorkflowRuntimeEndpoint.cs
- ReflectionUtil.cs
- StateChangeEvent.cs
- PointConverter.cs
- ReceiveSecurityHeaderElementManager.cs
- ObservableCollectionDefaultValueFactory.cs
- MULTI_QI.cs
- SkewTransform.cs
- Shared.cs
- ListViewTableCell.cs
- RouteCollection.cs
- RelationalExpressions.cs
- DataPagerCommandEventArgs.cs
- InfiniteIntConverter.cs
- CalendarDesigner.cs
- TypefaceCollection.cs
- EventSinkHelperWriter.cs
- DateBoldEvent.cs
- ZipIOLocalFileHeader.cs
- HtmlContainerControl.cs
- XsltContext.cs
- PromptEventArgs.cs
- Semaphore.cs
- WindowsGrip.cs
- WinEventTracker.cs
- CompoundFileIOPermission.cs
- unsafeIndexingFilterStream.cs
- Control.cs
- BufferModeSettings.cs
- TagMapInfo.cs
- DbSourceParameterCollection.cs
- ServerValidateEventArgs.cs
- followingsibling.cs
- DataGridViewCellParsingEventArgs.cs
- FontCacheUtil.cs
- FunctionQuery.cs
- WindowsGraphicsWrapper.cs
- ParameterCollectionEditorForm.cs
- Scene3D.cs
- InfoCardProofToken.cs
- SqlTriggerContext.cs
- DropDownHolder.cs
- TableLayoutStyleCollection.cs
- GetTokenRequest.cs
- SourceFileBuildProvider.cs
- ConfigurationValue.cs
- UserMapPath.cs
- HtmlSelect.cs
- StatusBar.cs
- ResourceProperty.cs
- WebPartConnectionsConnectVerb.cs
- ListItem.cs
- CustomErrorsSection.cs
- DataGridViewDataErrorEventArgs.cs
- Simplifier.cs
- ErrorFormatterPage.cs
- SmtpFailedRecipientsException.cs
- ViewGenResults.cs
- PanningMessageFilter.cs
- Accessible.cs
- PriorityBindingExpression.cs
- PackUriHelper.cs
- NativeMethodsOther.cs
- ProfessionalColors.cs
- XhtmlBasicLinkAdapter.cs
- ConstraintConverter.cs
- DbSourceParameterCollection.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- CustomMenuItemCollection.cs
- CategoryGridEntry.cs
- Classification.cs
- SecurityPermission.cs
- LinqDataSourceValidationException.cs
- EncodingInfo.cs
- WebPartConnectionsEventArgs.cs
- JapaneseLunisolarCalendar.cs
- SendSecurityHeader.cs
- ConnectionPoolManager.cs
- WebPartEditorCancelVerb.cs
- Int64AnimationBase.cs
- XmlEntity.cs
- TextSegment.cs
- FixedHighlight.cs
- MultipleViewProviderWrapper.cs
- LambdaCompiler.ControlFlow.cs
- IOThreadTimer.cs