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
- DataObjectSettingDataEventArgs.cs
- SafePointer.cs
- ObjectDataSourceWizardForm.cs
- TakeOrSkipWhileQueryOperator.cs
- HiddenFieldPageStatePersister.cs
- HttpConfigurationContext.cs
- PrivacyNoticeElement.cs
- DbMetaDataColumnNames.cs
- ObjectConverter.cs
- CacheEntry.cs
- TransactionManager.cs
- ExtendedTransformFactory.cs
- XmlJsonReader.cs
- AttributeCollection.cs
- SkewTransform.cs
- WebWorkflowRole.cs
- PackagePartCollection.cs
- NameSpaceExtractor.cs
- XmlSchemaCollection.cs
- ITreeGenerator.cs
- ProxyBuilder.cs
- ApplicationActivator.cs
- TextDecorationLocationValidation.cs
- ToolbarAUtomationPeer.cs
- DataTableMapping.cs
- CodeObject.cs
- EventToken.cs
- StyleModeStack.cs
- OutOfMemoryException.cs
- FloaterParaClient.cs
- BulletedListEventArgs.cs
- UTF32Encoding.cs
- WorkingDirectoryEditor.cs
- PatternMatcher.cs
- AnimationTimeline.cs
- FormattedTextSymbols.cs
- NestedContainer.cs
- FreeFormDragDropManager.cs
- Publisher.cs
- TableRowCollection.cs
- TrimSurroundingWhitespaceAttribute.cs
- ObjectDataSourceMethodEventArgs.cs
- CellParaClient.cs
- DataSourceExpressionCollection.cs
- GifBitmapEncoder.cs
- TextTreeTextBlock.cs
- DataGridViewRowEventArgs.cs
- XmlBoundElement.cs
- PartialArray.cs
- BitArray.cs
- SoapTypeAttribute.cs
- Gdiplus.cs
- PaintEvent.cs
- AxWrapperGen.cs
- PartitionedStream.cs
- UriParserTemplates.cs
- TextMarkerSource.cs
- Schedule.cs
- WebPartAuthorizationEventArgs.cs
- MenuItemBinding.cs
- MediaTimeline.cs
- BasicCellRelation.cs
- UidPropertyAttribute.cs
- XmlDesignerDataSourceView.cs
- Overlapped.cs
- StringStorage.cs
- SamlSerializer.cs
- LazyTextWriterCreator.cs
- RecordsAffectedEventArgs.cs
- WindowsListViewSubItem.cs
- PropertyDescriptorGridEntry.cs
- LocalizeDesigner.cs
- __ComObject.cs
- _SslStream.cs
- EntityParameter.cs
- OutputCacheProfile.cs
- ErrorTableItemStyle.cs
- EndOfStreamException.cs
- XamlSerializationHelper.cs
- WebPartManagerInternals.cs
- XmlHierarchicalEnumerable.cs
- SimpleWebHandlerParser.cs
- DefaultTraceListener.cs
- RangeValidator.cs
- ToolStripScrollButton.cs
- ItemDragEvent.cs
- ConditionalAttribute.cs
- AttachedAnnotation.cs
- XPathDocumentIterator.cs
- ColumnResult.cs
- Attributes.cs
- FileInfo.cs
- ProgramNode.cs
- WebPartConnectionsEventArgs.cs
- TextParagraphProperties.cs
- KernelTypeValidation.cs
- ToolStripDropDownButton.cs
- ColorConverter.cs
- CreateInstanceBinder.cs
- StringValidatorAttribute.cs