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
- DataGridHelper.cs
- ResourceExpressionBuilder.cs
- TriggerActionCollection.cs
- RoleManagerModule.cs
- FragmentQuery.cs
- ChangeTracker.cs
- UpWmlPageAdapter.cs
- OleDbParameterCollection.cs
- DelegatedStream.cs
- FloaterParagraph.cs
- WorkflowTimerService.cs
- SchemeSettingElement.cs
- MessagingDescriptionAttribute.cs
- ClientConfigPaths.cs
- SystemNetHelpers.cs
- WriterOutput.cs
- ClientOptions.cs
- RefExpr.cs
- UpdateTranslator.cs
- ZipIOLocalFileHeader.cs
- AppLevelCompilationSectionCache.cs
- XmlSchemaComplexType.cs
- Message.cs
- ConfigXmlSignificantWhitespace.cs
- SchemaLookupTable.cs
- Atom10FormatterFactory.cs
- DataGridViewTopRowAccessibleObject.cs
- SeekStoryboard.cs
- _Events.cs
- FormatVersion.cs
- Assembly.cs
- InkCollectionBehavior.cs
- TypedMessageConverter.cs
- SafeTimerHandle.cs
- TypedTableGenerator.cs
- GlyphRunDrawing.cs
- UIElement3DAutomationPeer.cs
- AsyncResult.cs
- XmlBinaryReader.cs
- TranslateTransform3D.cs
- FileResponseElement.cs
- KeysConverter.cs
- XmlUtil.cs
- DataStreams.cs
- NetworkInformationException.cs
- RecordBuilder.cs
- ConfigurationStrings.cs
- SystemInformation.cs
- DataGridViewCellPaintingEventArgs.cs
- _NegotiateClient.cs
- SecurityResources.cs
- ClientSettingsProvider.cs
- PickDesigner.xaml.cs
- BuildProviderAppliesToAttribute.cs
- BoundColumn.cs
- AutomationElementIdentifiers.cs
- BaseUriWithWildcard.cs
- PolicyValidationException.cs
- RuleSettingsCollection.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- SubpageParaClient.cs
- ScaleTransform.cs
- ConfigurationElement.cs
- GridViewPageEventArgs.cs
- AxisAngleRotation3D.cs
- NonParentingControl.cs
- XDRSchema.cs
- UIElementIsland.cs
- ResXResourceWriter.cs
- SingleObjectCollection.cs
- HScrollBar.cs
- RewritingSimplifier.cs
- UnescapedXmlDiagnosticData.cs
- SourceItem.cs
- DnsElement.cs
- ChannelSinkStacks.cs
- ErrorActivity.cs
- Currency.cs
- ActiveXMessageFormatter.cs
- RangeValuePattern.cs
- RegistrySecurity.cs
- AutoResizedEvent.cs
- TcpProcessProtocolHandler.cs
- StyleCollectionEditor.cs
- DPCustomTypeDescriptor.cs
- RemotingAttributes.cs
- DbConnectionPoolCounters.cs
- EntityDataSourceDesignerHelper.cs
- PropertyInformation.cs
- URLMembershipCondition.cs
- Int32Rect.cs
- EncoderParameters.cs
- QuotaThrottle.cs
- TextTreeNode.cs
- GridViewRow.cs
- CreateUserWizardDesigner.cs
- DrawingBrush.cs
- CodeTypeReferenceExpression.cs
- SamlSecurityToken.cs
- RowToFieldTransformer.cs