Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Data / System / Data / DefaultValueTypeConverter.cs / 1305376 / 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.
//
// [....]
// [....]
// [....]
//-----------------------------------------------------------------------------
/*
*/
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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SectionXmlInfo.cs
- ToolStripContentPanelDesigner.cs
- CompletionCallbackWrapper.cs
- path.cs
- EditingScopeUndoUnit.cs
- MatrixTransform3D.cs
- ScrollChrome.cs
- XD.cs
- SafeNativeMethodsCLR.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- CssTextWriter.cs
- WebPartAddingEventArgs.cs
- ToolStripSplitButton.cs
- BinaryNode.cs
- VBCodeProvider.cs
- EndpointDispatcherTable.cs
- ClientConfigurationHost.cs
- CodeGenHelper.cs
- SecurityTokenSerializer.cs
- DispatcherSynchronizationContext.cs
- PolygonHotSpot.cs
- TemplateBindingExtensionConverter.cs
- ProfileGroupSettings.cs
- EventProviderBase.cs
- X509ChainElement.cs
- NullableLongMinMaxAggregationOperator.cs
- BamlResourceDeserializer.cs
- SQLStringStorage.cs
- ContentValidator.cs
- _NetRes.cs
- CompositeCollection.cs
- TCEAdapterGenerator.cs
- ForwardPositionQuery.cs
- AsyncPostBackTrigger.cs
- Misc.cs
- Span.cs
- DatatypeImplementation.cs
- PropertyPushdownHelper.cs
- cookiecontainer.cs
- EntryPointNotFoundException.cs
- EDesignUtil.cs
- SimpleBitVector32.cs
- CommunicationException.cs
- RangeBaseAutomationPeer.cs
- CollaborationHelperFunctions.cs
- CodeCatchClauseCollection.cs
- XsdDateTime.cs
- AssemblyFilter.cs
- PageHandlerFactory.cs
- FilterElement.cs
- PageFunction.cs
- _DomainName.cs
- CacheDict.cs
- RoutedEventConverter.cs
- SqlPersonalizationProvider.cs
- ArraySortHelper.cs
- OracleString.cs
- ItemChangedEventArgs.cs
- Calendar.cs
- XPathScanner.cs
- BitmapEffectInput.cs
- HtmlTitle.cs
- _LazyAsyncResult.cs
- LoginStatusDesigner.cs
- FileDialogPermission.cs
- DefaultDiscoveryServiceExtension.cs
- WebBrowser.cs
- MimeObjectFactory.cs
- DbDataReader.cs
- TransactionInterop.cs
- DbConnectionPoolIdentity.cs
- ConfigXmlText.cs
- NonParentingControl.cs
- HTTPNotFoundHandler.cs
- ColumnMap.cs
- DetailsViewInsertedEventArgs.cs
- PresentationSource.cs
- PieceNameHelper.cs
- GeneralTransform3DTo2DTo3D.cs
- PackagePartCollection.cs
- Utils.cs
- DetailsViewRow.cs
- Panel.cs
- RoutedEventArgs.cs
- XDRSchema.cs
- MultipleViewProviderWrapper.cs
- ExpressionBuilder.cs
- XmlNodeChangedEventManager.cs
- EditorBrowsableAttribute.cs
- listitem.cs
- XmlExtensionFunction.cs
- MemoryPressure.cs
- SoapCommonClasses.cs
- HyperLinkStyle.cs
- ServiceModelInstallComponent.cs
- SpecularMaterial.cs
- FrameworkEventSource.cs
- ToolStripHighContrastRenderer.cs
- PopupRootAutomationPeer.cs
- FixedTextPointer.cs