Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / xsp / System / Web / UI / WebControls / HorizontalAlignConverter.cs / 1 / HorizontalAlignConverter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- // namespace System.Web.UI.WebControls { using System; using System.Collections; using System.ComponentModel; using System.Globalization; internal class HorizontalAlignConverter : EnumConverter { static string[] stringValues = new String[(int) HorizontalAlign.Justify + 1]; static HorizontalAlignConverter () { stringValues[(int) HorizontalAlign.NotSet] = "NotSet"; stringValues[(int) HorizontalAlign.Left] = "Left"; stringValues[(int) HorizontalAlign.Center] = "Center"; stringValues[(int) HorizontalAlign.Right] = "Right"; stringValues[(int) HorizontalAlign.Justify] = "Justify"; } // this constructor needs to be public despite the fact that it's in an internal // class so it can be created by Activator.CreateInstance. public HorizontalAlignConverter () : base(typeof(HorizontalAlign)) {} public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } else { return base.CanConvertFrom(context, sourceType); } } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value == null) return null; if (value is string) { string textValue = ((string)value).Trim(); if (textValue.Length == 0) return HorizontalAlign.NotSet; switch (textValue) { case "NotSet": return HorizontalAlign.NotSet; case "Left": return HorizontalAlign.Left; case "Center": return HorizontalAlign.Center; case "Right": return HorizontalAlign.Right; case "Justify": return HorizontalAlign.Justify; } } return base.ConvertFrom(context, culture, value); } public override bool CanConvertTo(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertTo(context, sourceType); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string) && ((int) value <= (int)HorizontalAlign.Justify)) { return stringValues[(int) value]; } return base.ConvertTo(context, culture, value, destinationType); } } }
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ActivityContext.cs
- IndexerNameAttribute.cs
- InfoCardCryptoHelper.cs
- StrongName.cs
- TextFormatterHost.cs
- PropertyConverter.cs
- ExpressionReplacer.cs
- PageAsyncTaskManager.cs
- UnsignedPublishLicense.cs
- EventLogPermissionAttribute.cs
- SQLDecimal.cs
- TypeBuilderInstantiation.cs
- XmlWriter.cs
- HashAlgorithm.cs
- RemotingConfigParser.cs
- Opcode.cs
- WebPartDeleteVerb.cs
- MsmqIntegrationElement.cs
- Scheduling.cs
- ComplexType.cs
- RegexStringValidatorAttribute.cs
- CompilerTypeWithParams.cs
- CoTaskMemHandle.cs
- Claim.cs
- ImagingCache.cs
- CompilationRelaxations.cs
- FontStretches.cs
- FocusWithinProperty.cs
- SolidColorBrush.cs
- ProcessThread.cs
- WindowClosedEventArgs.cs
- ObjectDataSource.cs
- DataFieldConverter.cs
- SystemColors.cs
- OutputCacheProfileCollection.cs
- RepeaterItem.cs
- ACE.cs
- ListenDesigner.cs
- SoapInteropTypes.cs
- RoutedEventValueSerializer.cs
- ListManagerBindingsCollection.cs
- ThicknessKeyFrameCollection.cs
- DocumentOrderQuery.cs
- BufferModeSettings.cs
- NodeFunctions.cs
- XmlAggregates.cs
- ObjectNavigationPropertyMapping.cs
- SafePEFileHandle.cs
- FacetChecker.cs
- CodeGenerator.cs
- XmlQueryType.cs
- QueryOutputWriter.cs
- WebPartCollection.cs
- ConvertEvent.cs
- Int16KeyFrameCollection.cs
- RIPEMD160.cs
- BulletChrome.cs
- IdentityModelStringsVersion1.cs
- ConfigXmlWhitespace.cs
- DataGridBoolColumn.cs
- SqlParameter.cs
- PropertyChangeTracker.cs
- StrongNameKeyPair.cs
- altserialization.cs
- JoinTreeNode.cs
- ObservableCollection.cs
- XsltLibrary.cs
- ColorConverter.cs
- DesigntimeLicenseContextSerializer.cs
- EmptyEnumerator.cs
- TcpClientChannel.cs
- AppSettingsSection.cs
- ClientTargetCollection.cs
- CallbackValidator.cs
- SafeReversePInvokeHandle.cs
- RuntimeIdentifierPropertyAttribute.cs
- DatePickerDateValidationErrorEventArgs.cs
- ServicePerformanceCounters.cs
- WebConfigurationHost.cs
- BinaryKeyIdentifierClause.cs
- XmlUrlResolver.cs
- ExtendedProtectionPolicyTypeConverter.cs
- XmlLinkedNode.cs
- ListViewHitTestInfo.cs
- TemplateManager.cs
- StrongNameUtility.cs
- DataGridViewHitTestInfo.cs
- RangeBaseAutomationPeer.cs
- EdmSchemaError.cs
- TableLayoutPanelResizeGlyph.cs
- DirectoryObjectSecurity.cs
- TargetException.cs
- ReadWriteObjectLock.cs
- DateTimeOffset.cs
- ObjectListComponentEditor.cs
- Stylesheet.cs
- StorageInfo.cs
- PassportAuthenticationEventArgs.cs
- GeneralTransform3DCollection.cs
- ConstNode.cs