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; ////// internal sealed class DefaultValueTypeConverter : StringConverter { private static string nullString = "Provides a type /// converter that can be used to populate a list box with available types. ///"; 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; ////// internal sealed class DefaultValueTypeConverter : StringConverter { private static string nullString = "Provides a type /// converter that can be used to populate a list box with available types. ///"; 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
- TimeoutValidationAttribute.cs
- ElementNotEnabledException.cs
- TokenBasedSet.cs
- Compilation.cs
- UnicastIPAddressInformationCollection.cs
- MethodCallConverter.cs
- Span.cs
- PointKeyFrameCollection.cs
- SqlErrorCollection.cs
- __TransparentProxy.cs
- x509utils.cs
- XmlEntity.cs
- DataRowComparer.cs
- StreamGeometryContext.cs
- ForeignKeyConstraint.cs
- DataGridViewCellValueEventArgs.cs
- StateWorkerRequest.cs
- PhysicalOps.cs
- StorageComplexPropertyMapping.cs
- MediaElementAutomationPeer.cs
- ZipIOExtraField.cs
- Frame.cs
- XpsSerializationManagerAsync.cs
- ProfileModule.cs
- SettingsSavedEventArgs.cs
- WebServiceFaultDesigner.cs
- FixedSOMLineCollection.cs
- SignatureHelper.cs
- TextStore.cs
- TemplateBuilder.cs
- XmlSchemaGroupRef.cs
- ObjectQueryState.cs
- EncoderNLS.cs
- TreeNodeSelectionProcessor.cs
- PowerModeChangedEventArgs.cs
- SqlBulkCopy.cs
- JsonByteArrayDataContract.cs
- ToolStripCodeDomSerializer.cs
- RichTextBoxDesigner.cs
- FollowerQueueCreator.cs
- ListItemViewAttribute.cs
- ProgressChangedEventArgs.cs
- ElapsedEventArgs.cs
- RawStylusActions.cs
- XmlSecureResolver.cs
- DocumentPageViewAutomationPeer.cs
- CompiledRegexRunnerFactory.cs
- DocumentReference.cs
- ChangeProcessor.cs
- BinaryFormatter.cs
- IOException.cs
- _RequestCacheProtocol.cs
- PackUriHelper.cs
- BitConverter.cs
- ReflectionPermission.cs
- BehaviorEditorPart.cs
- CrossContextChannel.cs
- UInt64Converter.cs
- GroupAggregateExpr.cs
- PtsContext.cs
- XmlSchemaSimpleContent.cs
- AppSettingsReader.cs
- XmlSchemaChoice.cs
- Facet.cs
- RadioButtonRenderer.cs
- JulianCalendar.cs
- FontDialog.cs
- LabelAutomationPeer.cs
- PhoneCallDesigner.cs
- PartialList.cs
- DataGridViewCellStyleChangedEventArgs.cs
- ConfigurationSection.cs
- ExtentKey.cs
- JoinElimination.cs
- WindowsBrush.cs
- HttpServerVarsCollection.cs
- configsystem.cs
- DataGridViewImageColumn.cs
- EntityDescriptor.cs
- VectorValueSerializer.cs
- ElementHostAutomationPeer.cs
- ImageInfo.cs
- SourceElementsCollection.cs
- ADConnectionHelper.cs
- base64Transforms.cs
- NameScopePropertyAttribute.cs
- DebuggerAttributes.cs
- HttpListener.cs
- XslTransformFileEditor.cs
- exports.cs
- NativeRecognizer.cs
- DataGridViewCellLinkedList.cs
- CodeArgumentReferenceExpression.cs
- DictionarySectionHandler.cs
- ReachDocumentPageSerializerAsync.cs
- backend.cs
- CompiledQuery.cs
- WinEventQueueItem.cs
- EntityTypeEmitter.cs
- CompiledRegexRunnerFactory.cs