Code:
                         / 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Data / System / Data / ColumnTypeConverter.cs / 1305376 / ColumnTypeConverter.cs
                        
                        
                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
//  
// [....]  
// [....] 
// [....]  
//----------------------------------------------------------------------------- 
/* 
 */
namespace System.Data {
    using System.ComponentModel;
    using System.ComponentModel.Design.Serialization; 
    using System.Diagnostics;
    using System.Globalization; 
    using System.Data.SqlTypes; 
    ///  
    ///    Provides a type
    ///       converter that can be used to populate a list box with available types. 
    ///  
    internal sealed class ColumnTypeConverter : TypeConverter { 
        private static Type[] types = new Type[] {
            typeof(Boolean), 
            typeof(Byte), 
            typeof(Byte[]),
            typeof(Char), 
            typeof(DateTime),
            typeof(Decimal),
            typeof(Double),
            typeof(Guid), 
            typeof(Int16),
            typeof(Int32), 
            typeof(Int64), 
            typeof(object),
            typeof(SByte), 
            typeof(Single),
            typeof(string),
            typeof(TimeSpan),
            typeof(UInt16), 
            typeof(UInt32),
            typeof(UInt64), 
            typeof(SqlInt16), 
            typeof(SqlInt32),
            typeof(SqlInt64), 
            typeof(SqlDecimal),
            typeof(SqlSingle),
            typeof(SqlDouble),
            typeof(SqlString), 
            typeof(SqlBoolean),
            typeof(SqlBinary), 
            typeof(SqlByte), 
            typeof(SqlDateTime),
            typeof(SqlGuid), 
            typeof(SqlMoney),
            typeof(SqlBytes),
            typeof(SqlChars),
            typeof(SqlXml) 
        };
        private StandardValuesCollection values; 
 
        // converter classes should have public ctor
        public ColumnTypeConverter() { 
        }
        /// 
        ///    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 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 String.Empty; 
                } 
                else {
                    value.ToString(); 
                }
            }
            if (value != null && destinationType == typeof(InstanceDescriptor)) {
                Object newValue = value; 
                if (value is string) {
                    for (int i = 0; i < types.Length; i++) { 
                        if (types[i].ToString().Equals(value)) 
                            newValue = types[i];
                    } 
                }
                if (value is Type || value is string) {
                    System.Reflection.MethodInfo method = typeof(Type).GetMethod("GetType", new Type[] {typeof(string)}); // change done for security review 
                    if (method != null) {
                        return new InstanceDescriptor(method, new object[] {((Type)newValue).AssemblyQualifiedName}); 
                    } 
                }
            } 
            return base.ConvertTo(context, culture, value, destinationType);
        }
 
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
            if (sourceType == typeof(string)) { 
                return true; 
            }
            return base.CanConvertTo(context, sourceType); 
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
            if (value != null && value.GetType() == typeof(string)) { 
                for (int i = 0; i < types.Length; i++) {
                    if (types[i].ToString().Equals(value)) 
                        return types[i]; 
                }
 
                return typeof(string);
            }
            return base.ConvertFrom(context, culture, value); 
        }
 
        ///  
        ///    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; 
        } 
    }
} 
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
//  
// [....]  
// [....] 
// [....]  
//----------------------------------------------------------------------------- 
/* 
 */
namespace System.Data {
    using System.ComponentModel;
    using System.ComponentModel.Design.Serialization; 
    using System.Diagnostics;
    using System.Globalization; 
    using System.Data.SqlTypes; 
    ///  
    ///    Provides a type
    ///       converter that can be used to populate a list box with available types. 
    ///  
    internal sealed class ColumnTypeConverter : TypeConverter { 
        private static Type[] types = new Type[] {
            typeof(Boolean), 
            typeof(Byte), 
            typeof(Byte[]),
            typeof(Char), 
            typeof(DateTime),
            typeof(Decimal),
            typeof(Double),
            typeof(Guid), 
            typeof(Int16),
            typeof(Int32), 
            typeof(Int64), 
            typeof(object),
            typeof(SByte), 
            typeof(Single),
            typeof(string),
            typeof(TimeSpan),
            typeof(UInt16), 
            typeof(UInt32),
            typeof(UInt64), 
            typeof(SqlInt16), 
            typeof(SqlInt32),
            typeof(SqlInt64), 
            typeof(SqlDecimal),
            typeof(SqlSingle),
            typeof(SqlDouble),
            typeof(SqlString), 
            typeof(SqlBoolean),
            typeof(SqlBinary), 
            typeof(SqlByte), 
            typeof(SqlDateTime),
            typeof(SqlGuid), 
            typeof(SqlMoney),
            typeof(SqlBytes),
            typeof(SqlChars),
            typeof(SqlXml) 
        };
        private StandardValuesCollection values; 
 
        // converter classes should have public ctor
        public ColumnTypeConverter() { 
        }
        /// 
        ///    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 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 String.Empty; 
                } 
                else {
                    value.ToString(); 
                }
            }
            if (value != null && destinationType == typeof(InstanceDescriptor)) {
                Object newValue = value; 
                if (value is string) {
                    for (int i = 0; i < types.Length; i++) { 
                        if (types[i].ToString().Equals(value)) 
                            newValue = types[i];
                    } 
                }
                if (value is Type || value is string) {
                    System.Reflection.MethodInfo method = typeof(Type).GetMethod("GetType", new Type[] {typeof(string)}); // change done for security review 
                    if (method != null) {
                        return new InstanceDescriptor(method, new object[] {((Type)newValue).AssemblyQualifiedName}); 
                    } 
                }
            } 
            return base.ConvertTo(context, culture, value, destinationType);
        }
 
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
            if (sourceType == typeof(string)) { 
                return true; 
            }
            return base.CanConvertTo(context, sourceType); 
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
            if (value != null && value.GetType() == typeof(string)) { 
                for (int i = 0; i < types.Length; i++) {
                    if (types[i].ToString().Equals(value)) 
                        return types[i]; 
                }
 
                return typeof(string);
            }
            return base.ConvertFrom(context, culture, value); 
        }
 
        ///  
        ///    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; 
        } 
    }
} 
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        
                        
                        
                        
                    Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StructuredType.cs
 - EmbeddedMailObject.cs
 - SrgsSemanticInterpretationTag.cs
 - XamlSerializationHelper.cs
 - DataContractSerializer.cs
 - WindowsScrollBarBits.cs
 - CodeTypeMember.cs
 - BorderGapMaskConverter.cs
 - InvocationExpression.cs
 - LogStream.cs
 - DataBinder.cs
 - ClientRolePrincipal.cs
 - Expressions.cs
 - TableLayoutSettings.cs
 - Triplet.cs
 - SortDescriptionCollection.cs
 - EventItfInfo.cs
 - NumericUpDown.cs
 - DataGridViewCellCancelEventArgs.cs
 - WebPartCatalogAddVerb.cs
 - Fonts.cs
 - PolicyException.cs
 - XPathMultyIterator.cs
 - Matrix.cs
 - PermissionSetTriple.cs
 - BindingMemberInfo.cs
 - EasingFunctionBase.cs
 - ScriptDescriptor.cs
 - FileStream.cs
 - PersonalizationProviderCollection.cs
 - GridPatternIdentifiers.cs
 - SubMenuStyleCollection.cs
 - XmlBuffer.cs
 - ObjectDataSourceFilteringEventArgs.cs
 - Base64Encoder.cs
 - DrawToolTipEventArgs.cs
 - MimeTypePropertyAttribute.cs
 - XmlNamespaceDeclarationsAttribute.cs
 - RemoteDebugger.cs
 - DocumentGridContextMenu.cs
 - QilParameter.cs
 - CodeMemberProperty.cs
 - X509Chain.cs
 - LineProperties.cs
 - BamlTreeMap.cs
 - DesignParameter.cs
 - CallbackValidatorAttribute.cs
 - TemplatePropertyEntry.cs
 - DateBoldEvent.cs
 - ZipIOLocalFileHeader.cs
 - GridPattern.cs
 - DesignerAdapterUtil.cs
 - Image.cs
 - TraceRecord.cs
 - HttpCookiesSection.cs
 - ThreadInterruptedException.cs
 - DecoratedNameAttribute.cs
 - CompositeDesignerAccessibleObject.cs
 - Aggregates.cs
 - BindingBase.cs
 - StyleReferenceConverter.cs
 - XmlILModule.cs
 - DataGridParentRows.cs
 - AsynchronousChannelMergeEnumerator.cs
 - RecommendedAsConfigurableAttribute.cs
 - EncoderParameter.cs
 - ScrollViewerAutomationPeer.cs
 - AssociationTypeEmitter.cs
 - DialogResultConverter.cs
 - SchemaCollectionPreprocessor.cs
 - CustomCredentialPolicy.cs
 - PartitionerQueryOperator.cs
 - DiscoveryServerProtocol.cs
 - ADMembershipProvider.cs
 - MenuItem.cs
 - NameNode.cs
 - DataGridViewAdvancedBorderStyle.cs
 - WebPartTransformer.cs
 - WebPartCatalogAddVerb.cs
 - ContextBase.cs
 - SqlDataSourceSummaryPanel.cs
 - Annotation.cs
 - documentsequencetextcontainer.cs
 - MembershipUser.cs
 - PointLight.cs
 - StandardToolWindows.cs
 - TextDecorationUnitValidation.cs
 - RotateTransform.cs
 - XamlTreeBuilder.cs
 - ErrorFormatterPage.cs
 - ColumnResizeUndoUnit.cs
 - MediaEntryAttribute.cs
 - IndependentlyAnimatedPropertyMetadata.cs
 - ResourceKey.cs
 - CommaDelimitedStringAttributeCollectionConverter.cs
 - CommandID.cs
 - RadioButton.cs
 - CachedRequestParams.cs
 - QilUnary.cs
 - TimeoutConverter.cs