Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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.
//
// [....]
// [....]
// [....]
//-----------------------------------------------------------------------------
/*
*/
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
- InvokePattern.cs
- Attributes.cs
- DynamicMethod.cs
- XmlIterators.cs
- WebBrowserEvent.cs
- ClientTarget.cs
- WebPartZoneBase.cs
- EntryPointNotFoundException.cs
- OrderPreservingSpoolingTask.cs
- log.cs
- HttpConfigurationSystem.cs
- EditCommandColumn.cs
- DataAdapter.cs
- BitStack.cs
- ConnectionPointCookie.cs
- SafeLocalAllocation.cs
- ComboBox.cs
- WebPartTracker.cs
- ExpressionBindings.cs
- HttpModuleCollection.cs
- GenericAuthenticationEventArgs.cs
- TreeViewAutomationPeer.cs
- KeyInstance.cs
- ColumnMap.cs
- SQlBooleanStorage.cs
- ApplicationSecurityInfo.cs
- TextBoxView.cs
- CompilerGeneratedAttribute.cs
- FloaterBaseParagraph.cs
- BamlLocalizabilityResolver.cs
- SamlEvidence.cs
- OracleBoolean.cs
- FileLogRecordStream.cs
- JpegBitmapEncoder.cs
- Speller.cs
- CustomErrorsSectionWrapper.cs
- IntersectQueryOperator.cs
- WindowsUpDown.cs
- InkCanvasAutomationPeer.cs
- ClientTargetSection.cs
- PropertyPathConverter.cs
- UIElementIsland.cs
- MULTI_QI.cs
- InstanceDataCollection.cs
- ProxyAssemblyNotLoadedException.cs
- Sentence.cs
- QuaternionRotation3D.cs
- SessionStateContainer.cs
- Overlapped.cs
- System.Data_BID.cs
- TypeGeneratedEventArgs.cs
- DataServiceQueryProvider.cs
- LogPolicy.cs
- BindingCollection.cs
- Errors.cs
- MsmqHostedTransportManager.cs
- InvalidEnumArgumentException.cs
- XMLSchema.cs
- FontFamilyIdentifier.cs
- XhtmlConformanceSection.cs
- HttpBrowserCapabilitiesWrapper.cs
- HttpCacheVaryByContentEncodings.cs
- KeyedHashAlgorithm.cs
- AddInDeploymentState.cs
- PnrpPeerResolver.cs
- DataObjectSettingDataEventArgs.cs
- GlobalizationSection.cs
- MessageQueuePermissionAttribute.cs
- ObjectStateEntryDbDataRecord.cs
- SimpleWorkerRequest.cs
- HttpRuntimeSection.cs
- EventLogException.cs
- ValueOfAction.cs
- TimerElapsedEvenArgs.cs
- ApplicationFileCodeDomTreeGenerator.cs
- HtmlWindow.cs
- InProcStateClientManager.cs
- DataReaderContainer.cs
- CompositeTypefaceMetrics.cs
- SqlDataSourceCommandEventArgs.cs
- SynchronizedPool.cs
- XmlSerializerNamespaces.cs
- CachedBitmap.cs
- PrivilegedConfigurationManager.cs
- HtmlEncodedRawTextWriter.cs
- RtType.cs
- AppSettingsSection.cs
- FileUtil.cs
- WebContext.cs
- TextBreakpoint.cs
- DetailsViewDeleteEventArgs.cs
- PeerNameRegistration.cs
- LogicalExpr.cs
- PersonalizableTypeEntry.cs
- WebRequest.cs
- MethodRental.cs
- SiteMapProvider.cs
- CheckBox.cs
- DataSourceXmlElementAttribute.cs
- ListenerSingletonConnectionReader.cs