Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- ClientConfigPaths.cs
- CardSpaceSelector.cs
- ArrayExtension.cs
- InfoCardX509Validator.cs
- RemoteWebConfigurationHostStream.cs
- namescope.cs
- ProgressBarBrushConverter.cs
- IndentTextWriter.cs
- UnmanagedMemoryStreamWrapper.cs
- Calendar.cs
- WindowsToolbar.cs
- FormsAuthenticationCredentials.cs
- ReaderWriterLockSlim.cs
- FastEncoder.cs
- CalendarItem.cs
- GenericTypeParameterBuilder.cs
- FixedSOMTable.cs
- WebPartMovingEventArgs.cs
- KeyToListMap.cs
- ImagingCache.cs
- IndicShape.cs
- CharacterMetricsDictionary.cs
- ExceptionUtil.cs
- TreeBuilder.cs
- MethodImplAttribute.cs
- ValidationError.cs
- ThreadStaticAttribute.cs
- SqlDataSourceCommandParser.cs
- DataGridPageChangedEventArgs.cs
- MultiSelectRootGridEntry.cs
- TextBox.cs
- MultipartContentParser.cs
- SHA384CryptoServiceProvider.cs
- XmlWriter.cs
- ProviderConnectionPoint.cs
- EmulateRecognizeCompletedEventArgs.cs
- Win32SafeHandles.cs
- AbsoluteQuery.cs
- StorageSetMapping.cs
- RootProfilePropertySettingsCollection.cs
- Atom10FormatterFactory.cs
- XmlName.cs
- NameSpaceEvent.cs
- XmlNotation.cs
- RuntimeEnvironment.cs
- TemplateControlBuildProvider.cs
- DesignTimeXamlWriter.cs
- Array.cs
- DataMemberConverter.cs
- TraceListeners.cs
- DataGridViewColumnCollectionDialog.cs
- PersonalizablePropertyEntry.cs
- SystemIPAddressInformation.cs
- NonNullItemCollection.cs
- Translator.cs
- TextCompositionEventArgs.cs
- URI.cs
- WindowsGraphicsWrapper.cs
- ValidateNames.cs
- RootDesignerSerializerAttribute.cs
- ObjectListFieldCollection.cs
- CodeDOMUtility.cs
- SessionEndingEventArgs.cs
- ConstraintCollection.cs
- Style.cs
- DecoderFallback.cs
- GenericTextProperties.cs
- HtmlObjectListAdapter.cs
- ResourceIDHelper.cs
- DataSourceCache.cs
- FormClosingEvent.cs
- SqlConnectionHelper.cs
- CreateUserWizardStep.cs
- ContractMapping.cs
- RijndaelManaged.cs
- DefaultMemberAttribute.cs
- BindingExpression.cs
- SamlAdvice.cs
- TransformerInfoCollection.cs
- DeclarationUpdate.cs
- AdCreatedEventArgs.cs
- DataList.cs
- SamlSecurityTokenAuthenticator.cs
- DirectoryGroupQuery.cs
- SecurityHeaderLayout.cs
- UnsafeNativeMethods.cs
- ReadOnlyDictionary.cs
- Helpers.cs
- EdmError.cs
- DefaultBindingPropertyAttribute.cs
- RenderContext.cs
- XmlSchemaParticle.cs
- NullExtension.cs
- XmlText.cs
- AsyncSerializedWorker.cs
- DataGridRowClipboardEventArgs.cs
- TemplateKey.cs
- SymmetricSecurityProtocolFactory.cs
- QfeChecker.cs
- LoginName.cs