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
- LockCookie.cs
- ReceiveSecurityHeaderEntry.cs
- HttpCacheVary.cs
- IPCCacheManager.cs
- ServiceBusyException.cs
- SecondaryViewProvider.cs
- WeakReadOnlyCollection.cs
- ControllableStoryboardAction.cs
- TextElement.cs
- PeerInputChannelListener.cs
- Emitter.cs
- CacheAxisQuery.cs
- StringAnimationBase.cs
- InfoCardSymmetricCrypto.cs
- SupportsEventValidationAttribute.cs
- Hyperlink.cs
- MenuEventArgs.cs
- FilteredDataSetHelper.cs
- CodeDelegateCreateExpression.cs
- CompilerState.cs
- PeerPresenceInfo.cs
- TrackingStringDictionary.cs
- HtmlInputPassword.cs
- DesignerActionTextItem.cs
- XmlSchemaNotation.cs
- LocalBuilder.cs
- Main.cs
- TimeZone.cs
- ElementHostAutomationPeer.cs
- XmlSecureResolver.cs
- GlobalItem.cs
- ExpressionVisitor.cs
- ProfileProvider.cs
- SchemaContext.cs
- FilteredReadOnlyMetadataCollection.cs
- HttpWriter.cs
- PartialCachingAttribute.cs
- ParallelEnumerable.cs
- TextEditorContextMenu.cs
- TextEditorCharacters.cs
- WmfPlaceableFileHeader.cs
- DataServiceContext.cs
- StatusBarItemAutomationPeer.cs
- Fonts.cs
- ClipboardData.cs
- ImageIndexConverter.cs
- AuthenticationConfig.cs
- SmtpReplyReader.cs
- WmpBitmapDecoder.cs
- PropertyDescriptorComparer.cs
- AnimationLayer.cs
- Vector3DAnimationUsingKeyFrames.cs
- ReadOnlyDataSourceView.cs
- CreateUserWizard.cs
- QueryPageSettingsEventArgs.cs
- DescendantBaseQuery.cs
- SemanticResolver.cs
- ExpressionSelection.cs
- PasswordTextNavigator.cs
- SessionStateContainer.cs
- CryptoKeySecurity.cs
- ToolBarButton.cs
- DetailsViewPageEventArgs.cs
- AliasedSlot.cs
- XmlMembersMapping.cs
- BaseTransportHeaders.cs
- VisualBrush.cs
- InstanceDataCollection.cs
- SmtpNetworkElement.cs
- PowerModeChangedEventArgs.cs
- KeyValuePair.cs
- CroppedBitmap.cs
- ExpandoObject.cs
- EngineSiteSapi.cs
- StoreItemCollection.cs
- TextBoxBaseDesigner.cs
- CheckBoxRenderer.cs
- XmlLoader.cs
- KoreanLunisolarCalendar.cs
- XmlAttributeOverrides.cs
- DesignerDataColumn.cs
- SqlUserDefinedAggregateAttribute.cs
- XmlAttributeProperties.cs
- EntityModelBuildProvider.cs
- TreeViewImageGenerator.cs
- DbConnectionStringBuilder.cs
- Translator.cs
- PackUriHelper.cs
- BinHexDecoder.cs
- GiveFeedbackEventArgs.cs
- HtmlInputSubmit.cs
- DataViewSetting.cs
- CollectionChangedEventManager.cs
- PenCursorManager.cs
- DependencyObjectType.cs
- ObfuscateAssemblyAttribute.cs
- ClientScriptManagerWrapper.cs
- SamlSecurityToken.cs
- SecurityToken.cs
- _RequestLifetimeSetter.cs