Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CompMod / System / ComponentModel / CharConverter.cs / 1305376 / CharConverter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.ComponentModel { using Microsoft.Win32; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.Runtime.Serialization.Formatters; using System.Runtime.Remoting; using System.Runtime.InteropServices; using System.Security.Permissions; ////// [HostProtection(SharedState = true)] public class CharConverter : TypeConverter { ///Provides /// a type converter to convert Unicode /// character objects to and from various other representations. ////// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertFrom(context, sourceType); } ///Gets a value indicating whether this converter can /// convert an object in the given source type to a Unicode character object using /// the specified context. ////// Converts the given object to another type. /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string) && value is char) { if ((char)value == (char)0) { return ""; } } return base.ConvertTo(context, culture, value, destinationType); } ////// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { string text = (string)value; if (text.Length > 1) { text = text.Trim(); } if (text != null && text.Length > 0) { if (text.Length != 1) { throw new FormatException(SR.GetString(SR.ConvertInvalidPrimitive, text, "Char")); } return text[0]; } return '\0'; } return base.ConvertFrom(context, culture, value); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //Converts the given object to a Unicode character object. ///// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.ComponentModel { using Microsoft.Win32; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.Runtime.Serialization.Formatters; using System.Runtime.Remoting; using System.Runtime.InteropServices; using System.Security.Permissions; ////// [HostProtection(SharedState = true)] public class CharConverter : TypeConverter { ///Provides /// a type converter to convert Unicode /// character objects to and from various other representations. ////// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertFrom(context, sourceType); } ///Gets a value indicating whether this converter can /// convert an object in the given source type to a Unicode character object using /// the specified context. ////// Converts the given object to another type. /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string) && value is char) { if ((char)value == (char)0) { return ""; } } return base.ConvertTo(context, culture, value, destinationType); } ////// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { string text = (string)value; if (text.Length > 1) { text = text.Trim(); } if (text != null && text.Length > 0) { if (text.Length != 1) { throw new FormatException(SR.GetString(SR.ConvertInvalidPrimitive, text, "Char")); } return text[0]; } return '\0'; } return base.ConvertFrom(context, culture, value); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.Converts the given object to a Unicode character object. ///
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ResourceProperty.cs
- MemberProjectionIndex.cs
- XmlTextEncoder.cs
- PartBasedPackageProperties.cs
- ProgressiveCrcCalculatingStream.cs
- InheritanceContextHelper.cs
- TdsParserHelperClasses.cs
- AssociationSetEnd.cs
- OletxEnlistment.cs
- SessionEndingCancelEventArgs.cs
- SymbolMethod.cs
- SqlCacheDependencySection.cs
- PropertyMetadata.cs
- QilInvoke.cs
- InputLangChangeEvent.cs
- DataBindingCollection.cs
- SafeLibraryHandle.cs
- HttpConfigurationSystem.cs
- Cursors.cs
- ListenerElementsCollection.cs
- DependencyPropertyHelper.cs
- EffectiveValueEntry.cs
- SortKey.cs
- TextCompositionManager.cs
- FontDriver.cs
- WindowsTooltip.cs
- EditableLabelControl.cs
- FileDialogCustomPlace.cs
- DoubleCollectionValueSerializer.cs
- Registration.cs
- TextParaClient.cs
- Conditional.cs
- WorkflowTimerService.cs
- Emitter.cs
- ZipQueryOperator.cs
- SelectionChangedEventArgs.cs
- Model3DGroup.cs
- PropertyChangedEventManager.cs
- Thread.cs
- WeakReferenceList.cs
- MethodBuilder.cs
- GridView.cs
- TypeDescriptionProviderAttribute.cs
- ClientScriptManagerWrapper.cs
- Stack.cs
- CookielessData.cs
- StreamUpdate.cs
- PathFigure.cs
- StorageMappingItemCollection.cs
- LinqDataSourceValidationException.cs
- Classification.cs
- ViewGenerator.cs
- BamlWriter.cs
- NonParentingControl.cs
- autovalidator.cs
- AdPostCacheSubstitution.cs
- ClassImporter.cs
- ToolStripSplitButton.cs
- RegexCompiler.cs
- OleDbReferenceCollection.cs
- OdbcConnectionHandle.cs
- ByteKeyFrameCollection.cs
- AttributeCallbackBuilder.cs
- SqlCommand.cs
- PrintDocument.cs
- DropTarget.cs
- DataGridViewCellParsingEventArgs.cs
- Typeface.cs
- SettingsPropertyNotFoundException.cs
- ReadOnlyMetadataCollection.cs
- UserControlBuildProvider.cs
- GrammarBuilderRuleRef.cs
- StyleSelector.cs
- ValidationManager.cs
- PropertyItem.cs
- GraphicsState.cs
- FilterEventArgs.cs
- EventLogPermission.cs
- dbenumerator.cs
- CrossContextChannel.cs
- SqlFlattener.cs
- MemoryFailPoint.cs
- DataGridViewCellCollection.cs
- RowUpdatingEventArgs.cs
- MetadataArtifactLoaderCompositeFile.cs
- __Filters.cs
- HwndHostAutomationPeer.cs
- ConfigurationElementProperty.cs
- BmpBitmapEncoder.cs
- ReferencedAssembly.cs
- SqlWriter.cs
- GcHandle.cs
- StylusSystemGestureEventArgs.cs
- AppliedDeviceFiltersDialog.cs
- CryptoStream.cs
- SegmentInfo.cs
- DurableEnlistmentState.cs
- TableLayoutSettingsTypeConverter.cs
- CssStyleCollection.cs
- DataSet.cs