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
- ContextMenu.cs
- DispatcherSynchronizationContext.cs
- OdbcPermission.cs
- ByteRangeDownloader.cs
- AdornerPresentationContext.cs
- ConfigurationSettings.cs
- NameValueConfigurationElement.cs
- MSAAEventDispatcher.cs
- ComboBox.cs
- ForeignKeyConstraint.cs
- MgmtConfigurationRecord.cs
- BitmapEffectRenderDataResource.cs
- UInt16Converter.cs
- WebPartAuthorizationEventArgs.cs
- XmlUtf8RawTextWriter.cs
- DesignerVerbCollection.cs
- ScrollContentPresenter.cs
- CommentAction.cs
- ColorIndependentAnimationStorage.cs
- HwndHostAutomationPeer.cs
- QueryContinueDragEventArgs.cs
- CodeTryCatchFinallyStatement.cs
- DataGridView.cs
- XmlCharType.cs
- ResXDataNode.cs
- SqlDependencyListener.cs
- Soap.cs
- BoundField.cs
- IndentedTextWriter.cs
- ValidateNames.cs
- DefaultDiscoveryServiceExtension.cs
- SmtpReplyReaderFactory.cs
- Interop.cs
- COM2PropertyPageUITypeConverter.cs
- ListViewSortEventArgs.cs
- LabelDesigner.cs
- Token.cs
- TabItemAutomationPeer.cs
- CompiledRegexRunner.cs
- Bitmap.cs
- WebErrorHandler.cs
- InputScopeNameConverter.cs
- AutomationIdentifier.cs
- CodeTypeDeclaration.cs
- ColorContextHelper.cs
- TextFormatterHost.cs
- WsiProfilesElementCollection.cs
- OrderedDictionary.cs
- SrgsRuleRef.cs
- SystemIcmpV4Statistics.cs
- SimpleWebHandlerParser.cs
- PagerSettings.cs
- JsonXmlDataContract.cs
- LassoSelectionBehavior.cs
- DesignOnlyAttribute.cs
- GridItem.cs
- PersonalizationAdministration.cs
- sqlinternaltransaction.cs
- CustomValidator.cs
- RegisteredHiddenField.cs
- RemoteWebConfigurationHost.cs
- DbMetaDataColumnNames.cs
- CodeAttributeArgumentCollection.cs
- SchemaTypeEmitter.cs
- RowToParametersTransformer.cs
- CuspData.cs
- StylusOverProperty.cs
- SiblingIterators.cs
- TreeNodeSelectionProcessor.cs
- OperationContractGenerationContext.cs
- SslStreamSecurityBindingElement.cs
- OpenFileDialog.cs
- FontDifferentiator.cs
- CultureInfoConverter.cs
- TextParaLineResult.cs
- ServiceInfo.cs
- TabControl.cs
- InfiniteTimeSpanConverter.cs
- HttpServerUtilityWrapper.cs
- ToolStripDropDownButton.cs
- IDReferencePropertyAttribute.cs
- IdentityHolder.cs
- HtmlEmptyTagControlBuilder.cs
- BrowserCapabilitiesCodeGenerator.cs
- ValueSerializer.cs
- coordinator.cs
- RIPEMD160.cs
- FlagsAttribute.cs
- _Rfc2616CacheValidators.cs
- Int32AnimationUsingKeyFrames.cs
- DependencyPropertyKind.cs
- ExpandCollapseProviderWrapper.cs
- DefaultHttpHandler.cs
- FormsAuthenticationModule.cs
- CultureTable.cs
- DocumentApplicationJournalEntry.cs
- SrgsDocument.cs
- CodeGotoStatement.cs
- TextRangeProviderWrapper.cs
- SudsCommon.cs