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
- XhtmlBasicPageAdapter.cs
- PopOutPanel.cs
- SectionRecord.cs
- AutoGeneratedFieldProperties.cs
- ContextMenuService.cs
- ProfileSettings.cs
- unsafeIndexingFilterStream.cs
- SiteMembershipCondition.cs
- StylusCollection.cs
- PhoneCallDesigner.cs
- MobileControlDesigner.cs
- AlternateViewCollection.cs
- SQLDouble.cs
- tooltip.cs
- HMACSHA512.cs
- ClientCultureInfo.cs
- TextPointerBase.cs
- CallContext.cs
- GetPageNumberCompletedEventArgs.cs
- ValidationSummary.cs
- itemelement.cs
- MembershipUser.cs
- ProgressBarHighlightConverter.cs
- CompilerTypeWithParams.cs
- PerformanceCounterNameAttribute.cs
- WindowsFormsSynchronizationContext.cs
- SafeThreadHandle.cs
- UnitySerializationHolder.cs
- Span.cs
- ImageKeyConverter.cs
- ParamArrayAttribute.cs
- BezierSegment.cs
- DependencyPropertyConverter.cs
- Profiler.cs
- EditorBrowsableAttribute.cs
- SplitterPanelDesigner.cs
- CultureTableRecord.cs
- IntegerValidatorAttribute.cs
- CodeBlockBuilder.cs
- SynchronizationLockException.cs
- ViewGenResults.cs
- DataSourceXmlClassAttribute.cs
- PathSegmentCollection.cs
- HitTestFilterBehavior.cs
- LicFileLicenseProvider.cs
- TextDecoration.cs
- XmlLoader.cs
- CodeCatchClause.cs
- XmlWrappingWriter.cs
- DuplicateWaitObjectException.cs
- SourceFileBuildProvider.cs
- Point3D.cs
- WpfPayload.cs
- RefExpr.cs
- WorkflowTerminatedException.cs
- ParagraphResult.cs
- BindingEntityInfo.cs
- FunctionMappingTranslator.cs
- hebrewshape.cs
- CachedRequestParams.cs
- CheckBoxRenderer.cs
- FixedPageProcessor.cs
- BaseTreeIterator.cs
- SafeLibraryHandle.cs
- MouseActionConverter.cs
- RoleManagerEventArgs.cs
- AffineTransform3D.cs
- InvalidPropValue.cs
- TrackingStringDictionary.cs
- SqlAggregateChecker.cs
- SpeechRecognitionEngine.cs
- FormClosingEvent.cs
- SvcMapFileLoader.cs
- SamlEvidence.cs
- VirtualizingPanel.cs
- WaitForChangedResult.cs
- HtmlAnchor.cs
- UnionQueryOperator.cs
- DiscoveryDefaults.cs
- CopyAttributesAction.cs
- ProxyWebPartManager.cs
- IIS7UserPrincipal.cs
- CompiledAction.cs
- RegionIterator.cs
- IdentityNotMappedException.cs
- COMException.cs
- columnmapfactory.cs
- ConditionValidator.cs
- ConstructorNeedsTagAttribute.cs
- ScriptServiceAttribute.cs
- MetaForeignKeyColumn.cs
- InheritedPropertyChangedEventArgs.cs
- storepermissionattribute.cs
- SchemaImporterExtensionsSection.cs
- DataSourceView.cs
- XmlQueryRuntime.cs
- UriTemplatePathPartiallyEquivalentSet.cs
- ReadOnlyCollection.cs
- ListItemConverter.cs
- ConstraintEnumerator.cs