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
- WorkflowMarkupSerializerMapping.cs
- SamlAuthenticationStatement.cs
- SimpleLine.cs
- WindowsListViewGroup.cs
- StringFreezingAttribute.cs
- XslException.cs
- CustomWebEventKey.cs
- AppModelKnownContentFactory.cs
- DetailsViewPagerRow.cs
- sqlcontext.cs
- JulianCalendar.cs
- HtmlElement.cs
- DataMisalignedException.cs
- MissingSatelliteAssemblyException.cs
- DataTableNewRowEvent.cs
- GroupByExpressionRewriter.cs
- XamlInt32CollectionSerializer.cs
- AsyncInvokeContext.cs
- NonPrimarySelectionGlyph.cs
- DetailsViewDeletedEventArgs.cs
- OdbcPermission.cs
- CodeSubDirectory.cs
- TextHidden.cs
- SecurityTraceRecordHelper.cs
- XmlMapping.cs
- DelegatedStream.cs
- PaginationProgressEventArgs.cs
- OutputCacheSettingsSection.cs
- DoubleCollectionConverter.cs
- GridProviderWrapper.cs
- CompositeActivityTypeDescriptor.cs
- WSHttpTransportSecurityElement.cs
- CfgSemanticTag.cs
- XmlDsigSep2000.cs
- StickyNote.cs
- GPPOINT.cs
- DocumentGridPage.cs
- GridItemCollection.cs
- SafeHandle.cs
- ListControl.cs
- DynamicResourceExtensionConverter.cs
- ScriptingSectionGroup.cs
- SelectionProcessor.cs
- WebPartConnectionsCancelEventArgs.cs
- XmlSchemaSequence.cs
- TextLineResult.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- SectionUpdates.cs
- Pens.cs
- TouchesOverProperty.cs
- Verify.cs
- JsonDataContract.cs
- SizeConverter.cs
- IDispatchConstantAttribute.cs
- ObjectDataSourceView.cs
- XmlSchemaSubstitutionGroup.cs
- FileLevelControlBuilderAttribute.cs
- SizeValueSerializer.cs
- SymmetricKey.cs
- ElementUtil.cs
- RoutedEventArgs.cs
- UnsafeNativeMethodsPenimc.cs
- ReferentialConstraint.cs
- XmlAnyElementAttributes.cs
- DrawingContextWalker.cs
- DataStreams.cs
- NavigationWindow.cs
- InteropBitmapSource.cs
- ContractReference.cs
- SafeRightsManagementHandle.cs
- AlphaSortedEnumConverter.cs
- CodeSnippetTypeMember.cs
- SecurityPolicySection.cs
- DataGridColumn.cs
- GridLengthConverter.cs
- MdiWindowListStrip.cs
- QualificationDataAttribute.cs
- XmlArrayItemAttributes.cs
- SQLDateTimeStorage.cs
- URIFormatException.cs
- WebPartActionVerb.cs
- CheckoutException.cs
- TextTreeTextElementNode.cs
- SystemResourceHost.cs
- SelectionEditor.cs
- ListViewItem.cs
- GridItemCollection.cs
- x509utils.cs
- ComponentCollection.cs
- StyleSheetDesigner.cs
- EventManager.cs
- DisposableCollectionWrapper.cs
- SQLMoneyStorage.cs
- GenericAuthenticationEventArgs.cs
- XPathItem.cs
- ScriptHandlerFactory.cs
- JoinTreeNode.cs
- ResourceDictionaryCollection.cs
- GPPOINTF.cs
- SafeThreadHandle.cs