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
- SqlDataSourceFilteringEventArgs.cs
- FontStretches.cs
- TCEAdapterGenerator.cs
- TextHidden.cs
- ToolStripPanelSelectionBehavior.cs
- LocalsItemDescription.cs
- CookieParameter.cs
- EllipticalNodeOperations.cs
- PopupRootAutomationPeer.cs
- WebPartConnectionsCancelEventArgs.cs
- XmlSchemaCollection.cs
- TextEditorSpelling.cs
- PinProtectionHelper.cs
- SynchronizedKeyedCollection.cs
- ErrorInfoXmlDocument.cs
- UserNameSecurityTokenProvider.cs
- WebFaultClientMessageInspector.cs
- HttpContextServiceHost.cs
- FacetChecker.cs
- OutputCache.cs
- PropertyIDSet.cs
- DataControlFieldCell.cs
- GlyphingCache.cs
- SamlAudienceRestrictionCondition.cs
- WebDescriptionAttribute.cs
- RMPublishingDialog.cs
- Accessible.cs
- EmptyCollection.cs
- CheckBox.cs
- UnaryNode.cs
- ToolStripItemBehavior.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- GridItemProviderWrapper.cs
- CurrentChangingEventArgs.cs
- ControlIdConverter.cs
- LambdaCompiler.Unary.cs
- MessageBox.cs
- GridView.cs
- ExceptionRoutedEventArgs.cs
- DataGridViewSelectedColumnCollection.cs
- SchemaObjectWriter.cs
- EnumerableValidator.cs
- MostlySingletonList.cs
- TypeBuilder.cs
- FrameworkTemplate.cs
- MailWebEventProvider.cs
- FontSource.cs
- CommonXSendMessage.cs
- XmlUrlResolver.cs
- SystemColorTracker.cs
- ContextMarshalException.cs
- DecoderFallback.cs
- DropDownButton.cs
- IPPacketInformation.cs
- XsdDataContractImporter.cs
- PassportAuthentication.cs
- CipherData.cs
- SecurityAlgorithmSuiteConverter.cs
- NumberAction.cs
- UpdatableWrapper.cs
- ConnectionInterfaceCollection.cs
- XamlBrushSerializer.cs
- ErrorFormatter.cs
- WindowsGraphics2.cs
- DataGridCellEditEndingEventArgs.cs
- SpellCheck.cs
- DefaultTextStoreTextComposition.cs
- UnmanagedHandle.cs
- WorkflowServiceNamespace.cs
- CatalogPart.cs
- ConsoleKeyInfo.cs
- AstTree.cs
- FindRequestContext.cs
- TypeGeneratedEventArgs.cs
- PerfCounterSection.cs
- StreamResourceInfo.cs
- HiddenFieldPageStatePersister.cs
- XmlTextEncoder.cs
- AssemblyAttributes.cs
- linebase.cs
- MenuRenderer.cs
- CmsInterop.cs
- CodeChecksumPragma.cs
- SafePEFileHandle.cs
- LoadedOrUnloadedOperation.cs
- OpacityConverter.cs
- PathSegment.cs
- FamilyMap.cs
- IODescriptionAttribute.cs
- PriorityItem.cs
- HttpDebugHandler.cs
- PathSegmentCollection.cs
- FixedSOMTable.cs
- CmsUtils.cs
- BinHexDecoder.cs
- Margins.cs
- SafeNativeMethods.cs
- FileRecordSequenceCompletedAsyncResult.cs
- WmpBitmapEncoder.cs
- PriorityQueue.cs