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
- MsmqMessageProperty.cs
- AdobeCFFWrapper.cs
- TabControlAutomationPeer.cs
- ValidationPropertyAttribute.cs
- TransformValueSerializer.cs
- PanelStyle.cs
- initElementDictionary.cs
- CuspData.cs
- ScheduleChanges.cs
- GenerateScriptTypeAttribute.cs
- ToolStripItemClickedEventArgs.cs
- DataGridViewCellStyleContentChangedEventArgs.cs
- ValidationEventArgs.cs
- AlternationConverter.cs
- DataTableClearEvent.cs
- DesignerTransactionCloseEvent.cs
- ParameterToken.cs
- XmlSerializationGeneratedCode.cs
- StrokeCollection2.cs
- X509Certificate2Collection.cs
- XmlAggregates.cs
- ReferenceEqualityComparer.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- BindingExpressionUncommonField.cs
- TextBlock.cs
- CodeEntryPointMethod.cs
- DrawListViewItemEventArgs.cs
- DiagnosticTraceSource.cs
- ContainsRowNumberChecker.cs
- DataColumnCollection.cs
- ObjectListItemCollection.cs
- MbpInfo.cs
- SecurityImpersonationBehavior.cs
- IApplicationTrustManager.cs
- SafeArchiveContext.cs
- TextRenderer.cs
- RelationHandler.cs
- DataSourceExpressionCollection.cs
- WindowsRegion.cs
- SymbolDocumentInfo.cs
- OneWayChannelListener.cs
- DesignBindingEditor.cs
- PropertySegmentSerializer.cs
- HttpFileCollection.cs
- PreviewControlDesigner.cs
- SymbolDocumentGenerator.cs
- SerializableAttribute.cs
- Size3D.cs
- __ConsoleStream.cs
- TimeSpanMinutesOrInfiniteConverter.cs
- SchemaManager.cs
- WebHttpBindingElement.cs
- Drawing.cs
- SystemFonts.cs
- XmlSchemaProviderAttribute.cs
- SoapEnumAttribute.cs
- DisplayNameAttribute.cs
- StringDictionary.cs
- TextEditorSpelling.cs
- EntityDataSourceReferenceGroup.cs
- SchemaNamespaceManager.cs
- ByteFacetDescriptionElement.cs
- FacetValues.cs
- XPathBinder.cs
- ObjectAssociationEndMapping.cs
- XmlChildNodes.cs
- TypedTableBaseExtensions.cs
- TextTreeText.cs
- StateRuntime.cs
- CommandDevice.cs
- AttachedPropertyBrowsableAttribute.cs
- CipherData.cs
- ResourcesGenerator.cs
- IdentityManager.cs
- AspNetHostingPermission.cs
- BooleanKeyFrameCollection.cs
- ActivityBindForm.Designer.cs
- ProcessHost.cs
- UITypeEditor.cs
- CheckBoxRenderer.cs
- ToolBar.cs
- ListViewTableCell.cs
- XPathItem.cs
- BaseTemplateParser.cs
- ClientSettings.cs
- UnsettableComboBox.cs
- InheritanceContextHelper.cs
- Trace.cs
- DateTimeStorage.cs
- TextRange.cs
- GlyphRunDrawing.cs
- TdsRecordBufferSetter.cs
- ComponentConverter.cs
- SpellerInterop.cs
- GridViewDeleteEventArgs.cs
- ComplexObject.cs
- GlyphRun.cs
- ResXDataNode.cs
- CodeTypeMember.cs
- IndentedWriter.cs