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;
///
/// Provides
/// a type converter to convert Unicode
/// character objects to and from various other representations.
///
[HostProtection(SharedState = true)]
public class CharConverter : TypeConverter {
///
/// 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.
///
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
if (sourceType == typeof(string)) {
return true;
}
return base.CanConvertFrom(context, sourceType);
}
///
/// 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);
}
///
/// Converts the given object to a Unicode character object.
///
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.
//------------------------------------------------------------------------------
//
// 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;
///
/// Provides
/// a type converter to convert Unicode
/// character objects to and from various other representations.
///
[HostProtection(SharedState = true)]
public class CharConverter : TypeConverter {
///
/// 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.
///
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
if (sourceType == typeof(string)) {
return true;
}
return base.CanConvertFrom(context, sourceType);
}
///
/// 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);
}
///
/// Converts the given object to a Unicode character object.
///
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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SQLDoubleStorage.cs
- ConfigUtil.cs
- InfoCardBinaryReader.cs
- EventLogEntry.cs
- WebRequestModuleElement.cs
- BitmapMetadataEnumerator.cs
- Wrapper.cs
- DiscriminatorMap.cs
- AmbientProperties.cs
- FileEnumerator.cs
- TaskFormBase.cs
- NavigatingCancelEventArgs.cs
- RenderingEventArgs.cs
- ListViewGroupCollectionEditor.cs
- VisualStyleTypesAndProperties.cs
- DayRenderEvent.cs
- XmlSchemaRedefine.cs
- AuthorizationRule.cs
- InputMethod.cs
- EpmSyndicationContentSerializer.cs
- XmlSchemaImport.cs
- DateTimeFormatInfoScanner.cs
- Separator.cs
- HttpStreamXmlDictionaryWriter.cs
- MessageRpc.cs
- DBBindings.cs
- TextBoxView.cs
- TypeUnloadedException.cs
- LinkedResource.cs
- DispatcherObject.cs
- SqlCommandBuilder.cs
- UnmanagedMarshal.cs
- CommandID.cs
- DataSourceCache.cs
- ExtensibleClassFactory.cs
- safemediahandle.cs
- UdpSocket.cs
- SqlUdtInfo.cs
- LogArchiveSnapshot.cs
- EventRouteFactory.cs
- DataFormat.cs
- RowToFieldTransformer.cs
- HttpCachePolicyWrapper.cs
- FrameworkRichTextComposition.cs
- InvalidPrinterException.cs
- DataServiceOperationContext.cs
- VerificationAttribute.cs
- Size3D.cs
- TickBar.cs
- EventMappingSettingsCollection.cs
- NeutralResourcesLanguageAttribute.cs
- DataFormats.cs
- Stylus.cs
- ArraySet.cs
- IndependentAnimationStorage.cs
- DiscoveryEndpointValidator.cs
- Header.cs
- FreeIndexList.cs
- NestedContainer.cs
- SignatureSummaryDialog.cs
- Empty.cs
- ReachFixedDocumentSerializer.cs
- OptimalBreakSession.cs
- HtmlWindowCollection.cs
- securitycriticaldataformultiplegetandset.cs
- XmlLanguage.cs
- FacetChecker.cs
- StrokeNode.cs
- SchemaNamespaceManager.cs
- hebrewshape.cs
- PersonalizableAttribute.cs
- ServiceParser.cs
- EntityDataSourceWrapperCollection.cs
- Formatter.cs
- EntityCommandDefinition.cs
- TimeEnumHelper.cs
- BitmapImage.cs
- PersonalizationStateInfo.cs
- Main.cs
- ChildDocumentBlock.cs
- SystemIcons.cs
- OrthographicCamera.cs
- AssemblyName.cs
- RelationshipNavigation.cs
- BatchWriter.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- ActivityExecutorOperation.cs
- WMIInterop.cs
- TimeSpan.cs
- TouchFrameEventArgs.cs
- XmlFileEditor.cs
- OrElse.cs
- baseaxisquery.cs
- Point3D.cs
- ImageBrush.cs
- HiddenField.cs
- DBCommand.cs
- DataGridColumnCollectionEditor.cs
- SmtpReplyReader.cs
- TypedRowHandler.cs