Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// 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
- SchemaCreator.cs
- WindowsFormsHost.cs
- WorkflowDefinitionContext.cs
- ClockController.cs
- CodeRemoveEventStatement.cs
- PointAnimationUsingPath.cs
- BufferModeSettings.cs
- OLEDB_Enum.cs
- ConfigXmlCDataSection.cs
- DataGridHelper.cs
- SqlDataSourceFilteringEventArgs.cs
- SafeEventLogReadHandle.cs
- MD5CryptoServiceProvider.cs
- MenuItem.cs
- IconBitmapDecoder.cs
- StylusPlugInCollection.cs
- Control.cs
- RelationshipConverter.cs
- OciEnlistContext.cs
- LogEntrySerializer.cs
- XmlNotation.cs
- MonitorWrapper.cs
- ScrollChrome.cs
- PlatformNotSupportedException.cs
- XmlNodeList.cs
- PreProcessInputEventArgs.cs
- Util.cs
- InstancePersistenceCommand.cs
- XmlAggregates.cs
- XPathNodeInfoAtom.cs
- DateTimeFormatInfo.cs
- FunctionImportMapping.cs
- Duration.cs
- ResourceAttributes.cs
- MetadataUtilsSmi.cs
- oledbmetadatacolumnnames.cs
- ZipIOExtraField.cs
- UnmanagedMarshal.cs
- WorkflowQueue.cs
- BitmapFrameDecode.cs
- KeyedPriorityQueue.cs
- DataPagerCommandEventArgs.cs
- WindowsImpersonationContext.cs
- ChtmlMobileTextWriter.cs
- EnumerableRowCollectionExtensions.cs
- TraceUtils.cs
- GridViewPageEventArgs.cs
- KerberosReceiverSecurityToken.cs
- ListSortDescription.cs
- Win32MouseDevice.cs
- QilReplaceVisitor.cs
- XslAstAnalyzer.cs
- MenuTracker.cs
- MimeWriter.cs
- UIElement3D.cs
- SmiContext.cs
- SystemWebSectionGroup.cs
- CollaborationHelperFunctions.cs
- HostSecurityManager.cs
- SelectionBorderGlyph.cs
- EntitySet.cs
- UnitySerializationHolder.cs
- MultipleViewPattern.cs
- BaseParagraph.cs
- PaginationProgressEventArgs.cs
- XmlMapping.cs
- RadioButtonFlatAdapter.cs
- SoapClientProtocol.cs
- ColumnResult.cs
- DynamicObject.cs
- MenuBase.cs
- MethodBuilder.cs
- GridItem.cs
- MediaContext.cs
- HtmlElementCollection.cs
- SqlGenerator.cs
- TrackBarDesigner.cs
- ResolveNameEventArgs.cs
- Utility.cs
- CompositeFontFamily.cs
- ImageBrush.cs
- ObjectSet.cs
- FolderLevelBuildProviderCollection.cs
- PerformanceCounterPermission.cs
- PathFigureCollectionConverter.cs
- ConfigurationLockCollection.cs
- CommonProperties.cs
- InvalidProgramException.cs
- BrowserInteropHelper.cs
- ResourceLoader.cs
- BrowsableAttribute.cs
- Tuple.cs
- DataTransferEventArgs.cs
- ProfileEventArgs.cs
- MemberInitExpression.cs
- TextProperties.cs
- BoundPropertyEntry.cs
- RayHitTestParameters.cs
- GlobalizationAssembly.cs
- JavaScriptObjectDeserializer.cs