Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- FamilyTypefaceCollection.cs
- Maps.cs
- FramingDecoders.cs
- PrivilegedConfigurationManager.cs
- DesignerDataSchemaClass.cs
- PointConverter.cs
- MouseBinding.cs
- GridViewRow.cs
- PositiveTimeSpanValidatorAttribute.cs
- PolicyLevel.cs
- MemoryResponseElement.cs
- recordstatefactory.cs
- ClientScriptItemCollection.cs
- XsdDataContractImporter.cs
- WebDisplayNameAttribute.cs
- DataConnectionHelper.cs
- CodeNamespaceImportCollection.cs
- ConstraintStruct.cs
- IntegerFacetDescriptionElement.cs
- XmlCustomFormatter.cs
- SqlDataSourceSelectingEventArgs.cs
- AlphaSortedEnumConverter.cs
- GridSplitterAutomationPeer.cs
- InteropExecutor.cs
- TargetException.cs
- future.cs
- DllNotFoundException.cs
- ImageFormatConverter.cs
- ClusterRegistryConfigurationProvider.cs
- SafeFileMappingHandle.cs
- CheckBoxList.cs
- RoleBoolean.cs
- PropertySegmentSerializationProvider.cs
- ProcessRequestAsyncResult.cs
- CompoundFileStorageReference.cs
- KeyboardNavigation.cs
- EnumCodeDomSerializer.cs
- SiteMapSection.cs
- IERequestCache.cs
- SimpleTextLine.cs
- Win32MouseDevice.cs
- CoreSwitches.cs
- NumericExpr.cs
- EmissiveMaterial.cs
- MaterializeFromAtom.cs
- UserControlParser.cs
- CallbackValidatorAttribute.cs
- SqlProfileProvider.cs
- HttpResponseInternalWrapper.cs
- InvalidAsynchronousStateException.cs
- RoutingTable.cs
- HelpEvent.cs
- SymLanguageVendor.cs
- PasswordBoxAutomationPeer.cs
- InkCollectionBehavior.cs
- TimeSpanSecondsConverter.cs
- MessageProperties.cs
- RegionIterator.cs
- DataServiceEntityAttribute.cs
- CompilerState.cs
- OleDbErrorCollection.cs
- StandardCommands.cs
- StringCollection.cs
- BuildManagerHost.cs
- AliasExpr.cs
- DataSetUtil.cs
- EmptyQuery.cs
- RandomNumberGenerator.cs
- ConfigurationSectionGroupCollection.cs
- InProcStateClientManager.cs
- WebScriptMetadataMessageEncoderFactory.cs
- Vector3DCollectionConverter.cs
- TreeViewDataItemAutomationPeer.cs
- OleDbConnectionInternal.cs
- LocalizableAttribute.cs
- KeyMatchBuilder.cs
- newinstructionaction.cs
- RsaKeyGen.cs
- DragDrop.cs
- CodeTypeMember.cs
- TabControlAutomationPeer.cs
- SoapWriter.cs
- PipelineComponent.cs
- FontWeight.cs
- InputScopeNameConverter.cs
- KeyValuePairs.cs
- CheckBoxField.cs
- IMembershipProvider.cs
- DataErrorValidationRule.cs
- SecurityDescriptor.cs
- AppModelKnownContentFactory.cs
- BasicCellRelation.cs
- SurrogateSelector.cs
- HttpCapabilitiesBase.cs
- MethodToken.cs
- DataGridHeaderBorder.cs
- SignatureToken.cs
- DashStyles.cs
- SchemaSetCompiler.cs
- ValueType.cs