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
- HttpInputStream.cs
- FontSourceCollection.cs
- CommonDialog.cs
- CommandExpr.cs
- RowCache.cs
- SiteMembershipCondition.cs
- ChangeTracker.cs
- StrokeNodeData.cs
- XmlChildEnumerator.cs
- GACMembershipCondition.cs
- RunInstallerAttribute.cs
- MonthChangedEventArgs.cs
- Claim.cs
- VectorAnimationUsingKeyFrames.cs
- WindowsListViewItemStartMenu.cs
- MessageFilterException.cs
- DataKeyCollection.cs
- PrimarySelectionAdorner.cs
- DynamicEntity.cs
- AutoGeneratedField.cs
- BuildProvider.cs
- TemplatePropertyEntry.cs
- MetadataItemEmitter.cs
- RelatedCurrencyManager.cs
- BindingList.cs
- MostlySingletonList.cs
- MatrixTransform.cs
- InteropDesigner.xaml.cs
- AssemblyBuilder.cs
- updateconfighost.cs
- SqlDataReader.cs
- ListenerConnectionDemuxer.cs
- TableSectionStyle.cs
- DataGridItemEventArgs.cs
- Ticks.cs
- RtType.cs
- StringInfo.cs
- FixedTextPointer.cs
- TextTreeObjectNode.cs
- initElementDictionary.cs
- RuleSetDialog.Designer.cs
- RijndaelManaged.cs
- dtdvalidator.cs
- basecomparevalidator.cs
- GetWorkflowTree.cs
- BamlRecordWriter.cs
- MailDefinition.cs
- DataListAutoFormat.cs
- Message.cs
- Int32Collection.cs
- JsonFormatReaderGenerator.cs
- Int64.cs
- AssertFilter.cs
- XmlILModule.cs
- InstrumentationTracker.cs
- ObjectDataSourceStatusEventArgs.cs
- PipeStream.cs
- XmlSchemaChoice.cs
- ScrollEvent.cs
- Visual3D.cs
- NativeBuffer.cs
- MimeParameterWriter.cs
- HandledMouseEvent.cs
- DbConnectionInternal.cs
- ProxyElement.cs
- JsonFormatReaderGenerator.cs
- WebPartVerb.cs
- WindowPattern.cs
- TemplatePropertyEntry.cs
- QueryableDataSourceEditData.cs
- streamingZipPartStream.cs
- FtpWebRequest.cs
- RootBrowserWindowProxy.cs
- QilInvoke.cs
- DataGridViewColumnDesigner.cs
- ListViewGroupConverter.cs
- SynchronizedInputAdaptor.cs
- DependencyProperty.cs
- AttributeEmitter.cs
- ConfigurationSectionCollection.cs
- NamedElement.cs
- ObjectIDGenerator.cs
- SpStreamWrapper.cs
- OdbcRowUpdatingEvent.cs
- Volatile.cs
- KeyValuePairs.cs
- User.cs
- PageRequestManager.cs
- DataSetFieldSchema.cs
- JsonFormatReaderGenerator.cs
- PageTheme.cs
- WrappedIUnknown.cs
- DataProtection.cs
- XpsPartBase.cs
- GridItem.cs
- ObjectDataSourceDisposingEventArgs.cs
- FrameAutomationPeer.cs
- SynchronizedCollection.cs
- RenderData.cs
- ResXBuildProvider.cs