Code:
/ DotNET / DotNET / 8.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
- SmtpException.cs
- LiteralLink.cs
- EntityDescriptor.cs
- AuthenticationService.cs
- Grant.cs
- _ScatterGatherBuffers.cs
- Speller.cs
- Sorting.cs
- DataKeyPropertyAttribute.cs
- CompiledIdentityConstraint.cs
- RTLAwareMessageBox.cs
- DataGridViewRowPrePaintEventArgs.cs
- Collection.cs
- QueryExecutionOption.cs
- NetStream.cs
- FtpWebRequest.cs
- Empty.cs
- LogRecordSequence.cs
- StyleCollection.cs
- Win32.cs
- EmulateRecognizeCompletedEventArgs.cs
- MetadataFile.cs
- assemblycache.cs
- CollectionConverter.cs
- PrintingPermissionAttribute.cs
- Size3D.cs
- PagePropertiesChangingEventArgs.cs
- TextServicesHost.cs
- ObjectReaderCompiler.cs
- AllowedAudienceUriElementCollection.cs
- TypedCompletedAsyncResult.cs
- HttpServerVarsCollection.cs
- ZoneButton.cs
- GridView.cs
- Animatable.cs
- HttpWebRequestElement.cs
- ViewStateException.cs
- TableRow.cs
- WindowsScrollBarBits.cs
- TrackingQueryElement.cs
- RightsManagementEncryptionTransform.cs
- _MultipleConnectAsync.cs
- UnionCodeGroup.cs
- UpdatePanelControlTrigger.cs
- DataSourceControlBuilder.cs
- PerformanceCounterPermissionEntry.cs
- documentation.cs
- ToolStripComboBox.cs
- CultureInfoConverter.cs
- WebProxyScriptElement.cs
- TdsRecordBufferSetter.cs
- HostTimeoutsElement.cs
- DBSqlParserTableCollection.cs
- ActivityScheduledQuery.cs
- DeviceContexts.cs
- LongTypeConverter.cs
- EdmPropertyAttribute.cs
- CompilationUtil.cs
- MembershipValidatePasswordEventArgs.cs
- Statements.cs
- HttpCacheVaryByContentEncodings.cs
- ViewBase.cs
- processwaithandle.cs
- XmlMapping.cs
- WebPartConnectVerb.cs
- ParserStreamGeometryContext.cs
- DesignOnlyAttribute.cs
- PanelStyle.cs
- _CommandStream.cs
- InputScopeAttribute.cs
- DataGridColumn.cs
- indexingfiltermarshaler.cs
- WrapPanel.cs
- ObjectDataSourceMethodEditor.cs
- DataSourceXmlAttributeAttribute.cs
- UpdateTracker.cs
- SimpleBitVector32.cs
- QueryMatcher.cs
- Range.cs
- PenContext.cs
- TableRowsCollectionEditor.cs
- ActivityBuilderXamlWriter.cs
- TreeViewHitTestInfo.cs
- SolidColorBrush.cs
- NativeMethodsCLR.cs
- Connection.cs
- ReadOnlyMetadataCollection.cs
- WindowsAuthenticationEventArgs.cs
- NumberSubstitution.cs
- SequenceRange.cs
- ScaleTransform.cs
- returneventsaver.cs
- MemberDescriptor.cs
- DesignerHelpers.cs
- NetCodeGroup.cs
- TableLayoutPanelCodeDomSerializer.cs
- QilChoice.cs
- cookie.cs
- Debugger.cs
- ProxyWebPartConnectionCollection.cs