Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / UI / WebControls / HorizontalAlignConverter.cs / 1305376 / 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); } } } // 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
- XPathException.cs
- Win32PrintDialog.cs
- EntityDataSourceStatementEditor.cs
- ScriptingScriptResourceHandlerSection.cs
- StoreItemCollection.Loader.cs
- WorkflowOperationBehavior.cs
- ClearCollection.cs
- ScrollItemPattern.cs
- MediaScriptCommandRoutedEventArgs.cs
- MethodBuilderInstantiation.cs
- GenericXmlSecurityToken.cs
- ContentOperations.cs
- WebPartMenu.cs
- DrawingServices.cs
- Configuration.cs
- DataGridLinkButton.cs
- newinstructionaction.cs
- IgnoreDeviceFilterElementCollection.cs
- MouseGestureValueSerializer.cs
- GB18030Encoding.cs
- GetRecipientListRequest.cs
- MemoryMappedView.cs
- HeaderFilter.cs
- PerformanceCounterCategory.cs
- ApplicationCommands.cs
- UdpDiscoveryMessageFilter.cs
- DocumentApplication.cs
- CaseDesigner.xaml.cs
- MobileSysDescriptionAttribute.cs
- StringFunctions.cs
- PhotoPrintingIntent.cs
- IsolationInterop.cs
- WebFaultException.cs
- DataTableClearEvent.cs
- GeneralTransform3D.cs
- RuntimeEnvironment.cs
- AccessKeyManager.cs
- ResourcePool.cs
- DataControlFieldHeaderCell.cs
- GeneralTransformCollection.cs
- OraclePermission.cs
- ValueSerializerAttribute.cs
- InputQueue.cs
- DataServiceQueryProvider.cs
- ArrayTypeMismatchException.cs
- LinqDataSourceDisposeEventArgs.cs
- XsdDataContractImporter.cs
- FileNameEditor.cs
- StrokeNodeOperations.cs
- RIPEMD160.cs
- PeerCollaborationPermission.cs
- PointAnimationUsingPath.cs
- TypeInfo.cs
- Highlights.cs
- HttpConfigurationSystem.cs
- SQLInt32.cs
- StorageBasedPackageProperties.cs
- ProfessionalColors.cs
- Assert.cs
- CollectionViewGroupRoot.cs
- MobileControlDesigner.cs
- CheckBox.cs
- GestureRecognitionResult.cs
- LiteralSubsegment.cs
- PaginationProgressEventArgs.cs
- ZoneIdentityPermission.cs
- RangeExpression.cs
- LocatorPartList.cs
- PointKeyFrameCollection.cs
- FileSecurity.cs
- ViewCellRelation.cs
- XmlSchemaException.cs
- TextRangeEditTables.cs
- MonitorWrapper.cs
- ListViewUpdateEventArgs.cs
- XmlNodeComparer.cs
- PolicyChain.cs
- VarRemapper.cs
- KeyValuePairs.cs
- ContractNamespaceAttribute.cs
- RawStylusInputReport.cs
- JournalEntry.cs
- EventBuilder.cs
- DirectoryLocalQuery.cs
- propertyentry.cs
- ConnectionsZone.cs
- OverflowException.cs
- TagPrefixCollection.cs
- CollectionChange.cs
- SQLBinaryStorage.cs
- CommandSet.cs
- X509Certificate2.cs
- DeviceContext.cs
- MediaCommands.cs
- SignedXml.cs
- SettingsPropertyNotFoundException.cs
- RegexFCD.cs
- DBSchemaTable.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs
- CompilerState.cs