Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- BrowserCapabilitiesCompiler.cs
- SuppressMergeCheckAttribute.cs
- ObjectListFieldCollection.cs
- ExceptionUtil.cs
- UITypeEditor.cs
- ItemsPanelTemplate.cs
- ExpandedWrapper.cs
- _CommandStream.cs
- LayoutTable.cs
- TextRenderer.cs
- XmlSerializerOperationBehavior.cs
- JsonEncodingStreamWrapper.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- Italic.cs
- ModelTreeEnumerator.cs
- HyperLinkDesigner.cs
- SystemIcmpV4Statistics.cs
- ToolBarButtonClickEvent.cs
- ItemsPanelTemplate.cs
- GridPatternIdentifiers.cs
- RegistrySecurity.cs
- SpellCheck.cs
- SqlDataSourceTableQuery.cs
- FastPropertyAccessor.cs
- PocoEntityKeyStrategy.cs
- SamlAuthorityBinding.cs
- StatusBarDrawItemEvent.cs
- XmlElementList.cs
- AssertValidation.cs
- sqlpipe.cs
- Int64Converter.cs
- ThicknessAnimationBase.cs
- SynchronizedKeyedCollection.cs
- DataGridViewAdvancedBorderStyle.cs
- EpmCustomContentWriterNodeData.cs
- EncryptedData.cs
- StateBag.cs
- ListViewInsertEventArgs.cs
- QueryTreeBuilder.cs
- XmlValueConverter.cs
- BamlResourceContent.cs
- SecurityTokenSerializer.cs
- CharacterString.cs
- ParameterExpression.cs
- PermissionRequestEvidence.cs
- AddInAttribute.cs
- MimeTypePropertyAttribute.cs
- Misc.cs
- Composition.cs
- ExitEventArgs.cs
- StringToken.cs
- HTTPNotFoundHandler.cs
- CollectionTraceRecord.cs
- xml.cs
- LoginDesignerUtil.cs
- QueryTask.cs
- RecordConverter.cs
- GridProviderWrapper.cs
- EmissiveMaterial.cs
- WindowsPrincipal.cs
- TrackingStringDictionary.cs
- FactoryMaker.cs
- DataExpression.cs
- RangeValuePattern.cs
- StreamGeometry.cs
- XhtmlTextWriter.cs
- EventSetterHandlerConverter.cs
- OpCellTreeNode.cs
- MetadataSerializer.cs
- DeclarativeCatalogPart.cs
- PersistenceTypeAttribute.cs
- SessionPageStateSection.cs
- LongTypeConverter.cs
- SmtpAuthenticationManager.cs
- Action.cs
- ActiveXSite.cs
- ListenerConstants.cs
- AdapterUtil.cs
- datacache.cs
- ServiceBehaviorAttribute.cs
- StylusEditingBehavior.cs
- XslVisitor.cs
- wpf-etw.cs
- _AuthenticationState.cs
- SmtpFailedRecipientException.cs
- SupportsPreviewControlAttribute.cs
- FontFamily.cs
- ProviderConnectionPoint.cs
- ScrollPattern.cs
- TransportConfigurationTypeElementCollection.cs
- SpAudioStreamWrapper.cs
- UserControlCodeDomTreeGenerator.cs
- EntityConnectionStringBuilderItem.cs
- UserMapPath.cs
- Normalization.cs
- GenericEnumConverter.cs
- XmlILConstructAnalyzer.cs
- FormViewDeletedEventArgs.cs
- MarginCollapsingState.cs
- DataMemberFieldConverter.cs