Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Data / System / Data / DefaultValueTypeConverter.cs / 1 / DefaultValueTypeConverter.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;
///
/// Provides a type
/// converter that can be used to populate a list box with available types.
///
internal sealed class DefaultValueTypeConverter : StringConverter {
private static string nullString = "";
private static string dbNullString = "";
// converter classes should have public ctor
public DefaultValueTypeConverter() {
}
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 nullString;
}
else if (value == DBNull.Value) {
return dbNullString;
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
if (value != null && value.GetType() == typeof(string)) {
string strValue = (string)value;
if (string.Compare(strValue, nullString, StringComparison.OrdinalIgnoreCase) == 0)
return null;
else if (string.Compare(strValue, dbNullString, StringComparison.OrdinalIgnoreCase) == 0)
return DBNull.Value;
}
return base.ConvertFrom(context, culture, value);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SystemUnicastIPAddressInformation.cs
- ServiceOperationParameter.cs
- Context.cs
- AnnotationAdorner.cs
- NativeMethods.cs
- SinglePhaseEnlistment.cs
- Vector.cs
- GeometryHitTestParameters.cs
- XmlAtomicValue.cs
- SqlDataSource.cs
- Win32PrintDialog.cs
- FilteredXmlReader.cs
- XmlDigitalSignatureProcessor.cs
- CommonGetThemePartSize.cs
- CalendarTable.cs
- AvTraceFormat.cs
- PersianCalendar.cs
- AnnotationResourceCollection.cs
- XmlCDATASection.cs
- PointCollectionValueSerializer.cs
- CompilerCollection.cs
- PackageRelationshipSelector.cs
- IDataContractSurrogate.cs
- LocalizationComments.cs
- TextDecorationUnitValidation.cs
- Rect3D.cs
- EqualityComparer.cs
- ChannelTokenTypeConverter.cs
- Thread.cs
- AlternateView.cs
- Overlapped.cs
- ProcessHostServerConfig.cs
- GZipStream.cs
- HttpContextServiceHost.cs
- WebHttpSecurityModeHelper.cs
- TreeViewItem.cs
- ModelProperty.cs
- SEHException.cs
- HostProtectionPermission.cs
- HtmlLink.cs
- Recipient.cs
- XmlRootAttribute.cs
- BuildManagerHost.cs
- UnsettableComboBox.cs
- EntityDataSourceChangingEventArgs.cs
- BaseCollection.cs
- ChannelEndpointElementCollection.cs
- DynamicResourceExtension.cs
- PerformanceCounterTraceRecord.cs
- StreamGeometryContext.cs
- CheckBoxField.cs
- AttachmentService.cs
- DbConnectionPoolGroup.cs
- TextBoxBase.cs
- PageRequestManager.cs
- SqlWebEventProvider.cs
- JpegBitmapDecoder.cs
- WebPartCloseVerb.cs
- BuildResult.cs
- controlskin.cs
- HeaderedContentControl.cs
- OracleCommandSet.cs
- XmlHierarchicalDataSourceView.cs
- HandledMouseEvent.cs
- TrackingProfileDeserializationException.cs
- ellipse.cs
- TypeNameConverter.cs
- SafeCryptoKeyHandle.cs
- WinInet.cs
- SqlServer2KCompatibilityCheck.cs
- FlowPosition.cs
- CLRBindingWorker.cs
- _DomainName.cs
- HttpListener.cs
- FontClient.cs
- AddressingVersion.cs
- NestPullup.cs
- MessageQueue.cs
- ProtectedConfiguration.cs
- MulticastDelegate.cs
- PriorityChain.cs
- DurableOperationContext.cs
- XappLauncher.cs
- TextEditorMouse.cs
- ControlEvent.cs
- DoubleAnimationBase.cs
- MonitoringDescriptionAttribute.cs
- Geometry3D.cs
- HyperLinkStyle.cs
- LayoutManager.cs
- ConnectionOrientedTransportChannelListener.cs
- X509Certificate2.cs
- MapPathBasedVirtualPathProvider.cs
- WS2007HttpBindingCollectionElement.cs
- InputScope.cs
- TaskDesigner.cs
- SqlWriter.cs
- RandomNumberGenerator.cs
- IndexOutOfRangeException.cs
- invalidudtexception.cs