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
- GeometryCollection.cs
- PrintPageEvent.cs
- SystemNetHelpers.cs
- FormViewModeEventArgs.cs
- ClientData.cs
- NotifyIcon.cs
- arabicshape.cs
- FormatException.cs
- HtmlForm.cs
- PerformanceCounterPermissionAttribute.cs
- ListViewDeleteEventArgs.cs
- controlskin.cs
- XmlAttribute.cs
- WmlTextViewAdapter.cs
- WindowsFont.cs
- ProcessHostFactoryHelper.cs
- ServiceAuthorizationManager.cs
- ConstraintManager.cs
- AttributeSetAction.cs
- securitycriticaldata.cs
- CodeArrayCreateExpression.cs
- _AutoWebProxyScriptHelper.cs
- _NetworkingPerfCounters.cs
- Cursor.cs
- SafeJobHandle.cs
- Column.cs
- Transform.cs
- MobileControlsSectionHelper.cs
- CompiledQueryCacheKey.cs
- VectorValueSerializer.cs
- FrameSecurityDescriptor.cs
- ListViewItemEventArgs.cs
- MapPathBasedVirtualPathProvider.cs
- ItemChangedEventArgs.cs
- StructuredTypeEmitter.cs
- MetadataItemSerializer.cs
- ReachFixedDocumentSerializer.cs
- TextCompositionEventArgs.cs
- OracleCommand.cs
- OleDbErrorCollection.cs
- FrameworkElementFactoryMarkupObject.cs
- ModuleBuilder.cs
- wmiprovider.cs
- WebEventCodes.cs
- SrgsItemList.cs
- SafeNativeMemoryHandle.cs
- HtmlControl.cs
- HtmlTableRowCollection.cs
- RangeValuePattern.cs
- DragDropHelper.cs
- Variable.cs
- WebContext.cs
- StringUtil.cs
- EventLogEntryCollection.cs
- SystemNetHelpers.cs
- MenuBase.cs
- SqlClientWrapperSmiStreamChars.cs
- Configuration.cs
- TagMapCollection.cs
- XmlLangPropertyAttribute.cs
- StructuralCache.cs
- ElementsClipboardData.cs
- XPathMultyIterator.cs
- ManagementObject.cs
- EventTrigger.cs
- ReachSerializationUtils.cs
- BidOverLoads.cs
- InvalidPrinterException.cs
- OdbcParameterCollection.cs
- Configuration.cs
- Rijndael.cs
- nulltextcontainer.cs
- BitVec.cs
- EventPrivateKey.cs
- ButtonBaseAdapter.cs
- EventSetter.cs
- EpmSourceTree.cs
- _NtlmClient.cs
- DataGridViewCellFormattingEventArgs.cs
- ApplicationContext.cs
- UriTemplateTableMatchCandidate.cs
- DrawingAttributesDefaultValueFactory.cs
- ToolStripDropDownClosingEventArgs.cs
- DesignDataSource.cs
- UnionQueryOperator.cs
- ContextMenuStrip.cs
- AvTrace.cs
- EventItfInfo.cs
- TextEncodedRawTextWriter.cs
- DynamicValidatorEventArgs.cs
- DataServiceHostFactory.cs
- BroadcastEventHelper.cs
- WebPageTraceListener.cs
- TypeLibConverter.cs
- InputLanguageManager.cs
- ContentElement.cs
- HtmlInputSubmit.cs
- ControlBindingsCollection.cs
- GroupBoxRenderer.cs
- TypedElement.cs