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
- PrintPreviewGraphics.cs
- ReachSerializableProperties.cs
- WebPartConnectionsCancelVerb.cs
- ReferenceEqualityComparer.cs
- XmlToDatasetMap.cs
- ClientRolePrincipal.cs
- TrustLevel.cs
- GeometryModel3D.cs
- SaveFileDialog.cs
- XhtmlBasicImageAdapter.cs
- SourceInterpreter.cs
- CollectionViewGroupRoot.cs
- SystemNetHelpers.cs
- MachineKeyConverter.cs
- OperatingSystem.cs
- Workspace.cs
- OracleTransaction.cs
- PlanCompiler.cs
- TimeSpanValidator.cs
- DescendantBaseQuery.cs
- DocumentGrid.cs
- Accessors.cs
- SerializationInfo.cs
- HtmlInputHidden.cs
- HtmlLink.cs
- MaskDescriptor.cs
- TextBoxBase.cs
- ColorBlend.cs
- WindowAutomationPeer.cs
- CancelEventArgs.cs
- ScrollPattern.cs
- DateTimeValueSerializerContext.cs
- CustomMenuItemCollection.cs
- AsymmetricSignatureFormatter.cs
- DesignerListAdapter.cs
- EnumBuilder.cs
- SpellerInterop.cs
- DataGridSortCommandEventArgs.cs
- ProxyGenerator.cs
- XmlDownloadManager.cs
- RectangleGeometry.cs
- RightNameExpirationInfoPair.cs
- Group.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- TableNameAttribute.cs
- PocoEntityKeyStrategy.cs
- DesignerRegion.cs
- DesignerAutoFormat.cs
- XNodeValidator.cs
- ChannelDispatcherCollection.cs
- HwndSourceParameters.cs
- BitmapEffect.cs
- Metafile.cs
- XmlWhitespace.cs
- BitmapEffectDrawingContextWalker.cs
- HyperLinkDesigner.cs
- XmlCharCheckingWriter.cs
- DataGridViewCell.cs
- SetterBase.cs
- Scene3D.cs
- RefreshEventArgs.cs
- DocumentGridPage.cs
- AttachmentCollection.cs
- BufferAllocator.cs
- BitmapCodecInfoInternal.cs
- HtmlProps.cs
- SrgsElement.cs
- HostVisual.cs
- TemplateInstanceAttribute.cs
- SimpleBitVector32.cs
- ColumnMapVisitor.cs
- XmlEntityReference.cs
- XpsSerializerFactory.cs
- X509CertificateValidator.cs
- FontWeights.cs
- _LoggingObject.cs
- DataGridViewCellStyleConverter.cs
- TemplatedMailWebEventProvider.cs
- ConnectionAcceptor.cs
- FastPropertyAccessor.cs
- InfoCardBinaryReader.cs
- DateTimeValueSerializer.cs
- GeneralTransform2DTo3D.cs
- AutomationPropertyInfo.cs
- CodeExporter.cs
- WebPartEditorCancelVerb.cs
- ToolStripPanel.cs
- FontStretches.cs
- HttpRuntimeSection.cs
- DomainConstraint.cs
- CodeLinePragma.cs
- RootBrowserWindowAutomationPeer.cs
- MsmqProcessProtocolHandler.cs
- mda.cs
- ContainerVisual.cs
- ImageAutomationPeer.cs
- InplaceBitmapMetadataWriter.cs
- RadioButtonFlatAdapter.cs
- ConfigXmlElement.cs
- SqlNotificationRequest.cs