Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / CompMod / System / ComponentModel / CharConverter.cs / 1 / 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
- DataPagerFieldCommandEventArgs.cs
- HashSetEqualityComparer.cs
- QuaternionAnimation.cs
- KnownTypesProvider.cs
- XmlSchemaGroup.cs
- RSACryptoServiceProvider.cs
- PostBackOptions.cs
- MsmqIntegrationAppDomainProtocolHandler.cs
- MetadataPropertyAttribute.cs
- SectionVisual.cs
- ConvertEvent.cs
- Evaluator.cs
- PasswordRecoveryAutoFormat.cs
- SerializationAttributes.cs
- Margins.cs
- RSAOAEPKeyExchangeFormatter.cs
- WebCategoryAttribute.cs
- EnumValAlphaComparer.cs
- WsdlBuildProvider.cs
- SizeConverter.cs
- FunctionCommandText.cs
- TimeoutConverter.cs
- BookmarkScopeHandle.cs
- DataGridViewCellStyleContentChangedEventArgs.cs
- StringValidatorAttribute.cs
- CheckableControlBaseAdapter.cs
- TextBoxDesigner.cs
- SiteMapDataSource.cs
- _ConnectStream.cs
- BitmapImage.cs
- PointAnimation.cs
- odbcmetadatacollectionnames.cs
- ClassicBorderDecorator.cs
- TextServicesLoader.cs
- NavigationEventArgs.cs
- CommonRemoteMemoryBlock.cs
- SynchronizingStream.cs
- SearchForVirtualItemEventArgs.cs
- RIPEMD160Managed.cs
- PermissionListSet.cs
- DataControlButton.cs
- CategoryAttribute.cs
- RelatedCurrencyManager.cs
- EntityCommand.cs
- _emptywebproxy.cs
- NativeMethods.cs
- ExtendedProtectionPolicyElement.cs
- DataGridTextBoxColumn.cs
- WindowsScrollBarBits.cs
- Italic.cs
- MenuCommands.cs
- QilReplaceVisitor.cs
- ConstantSlot.cs
- StringResourceManager.cs
- SmiGettersStream.cs
- MaskedTextProvider.cs
- DebuggerAttributes.cs
- OperationAbortedException.cs
- LinqMaximalSubtreeNominator.cs
- InvalidProgramException.cs
- Codec.cs
- ObjectListCommand.cs
- PictureBox.cs
- PassportPrincipal.cs
- _LocalDataStoreMgr.cs
- xmlsaver.cs
- NullableFloatSumAggregationOperator.cs
- SqlStream.cs
- InertiaRotationBehavior.cs
- SequentialOutput.cs
- SmiEventSink_Default.cs
- ISO2022Encoding.cs
- WebHttpBindingElement.cs
- Single.cs
- dataobject.cs
- LinqDataSourceInsertEventArgs.cs
- ScriptComponentDescriptor.cs
- BindingList.cs
- Brush.cs
- ConvertEvent.cs
- Matrix3D.cs
- WebReferencesBuildProvider.cs
- DataKeyCollection.cs
- SynchronizationHandlesCodeDomSerializer.cs
- FieldAccessException.cs
- SQLByte.cs
- MenuItemCollection.cs
- CalendarDay.cs
- Underline.cs
- MetadataPropertyCollection.cs
- TextWriterTraceListener.cs
- coordinatorscratchpad.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- InputScopeAttribute.cs
- SystemIPGlobalStatistics.cs
- TypeConverter.cs
- PartialTrustVisibleAssembliesSection.cs
- PeerCollaboration.cs
- BackStopAuthenticationModule.cs
- OracleCommandSet.cs