Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / 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. //------------------------------------------------------------------------------ //// 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ListViewItemEventArgs.cs
- RectangleConverter.cs
- BitmapEncoder.cs
- UriScheme.cs
- Array.cs
- CodeConstructor.cs
- SiteMapPath.cs
- SubpageParaClient.cs
- DiscreteKeyFrames.cs
- BitmapEffectInputConnector.cs
- compensatingcollection.cs
- JoinGraph.cs
- SecurityContext.cs
- RecognizeCompletedEventArgs.cs
- XmlSerializer.cs
- CmsUtils.cs
- TextParaClient.cs
- RawStylusActions.cs
- PagesChangedEventArgs.cs
- Stack.cs
- ImageInfo.cs
- GridViewColumnHeaderAutomationPeer.cs
- DeobfuscatingStream.cs
- IfAction.cs
- StreamWriter.cs
- ObjectComplexPropertyMapping.cs
- TypeUnloadedException.cs
- SAPICategories.cs
- TrustSection.cs
- NetPeerTcpBindingElement.cs
- ActiveXMessageFormatter.cs
- HttpCapabilitiesSectionHandler.cs
- BindingsCollection.cs
- AssemblyCacheEntry.cs
- MetadataUtilsSmi.cs
- MessageSecurityOverTcpElement.cs
- DataGridViewDataErrorEventArgs.cs
- UIElement.cs
- NavigationHelper.cs
- FormViewDeleteEventArgs.cs
- SolidBrush.cs
- XmlAttributeCollection.cs
- EventLogWatcher.cs
- ToolStripContainer.cs
- BinaryKeyIdentifierClause.cs
- BuildManager.cs
- Error.cs
- TdsValueSetter.cs
- XmlArrayItemAttribute.cs
- IPEndPoint.cs
- Vector3DCollection.cs
- Barrier.cs
- ToolStripTextBox.cs
- NetCodeGroup.cs
- RequestCachingSection.cs
- CommonProperties.cs
- DataGridViewCellLinkedList.cs
- LogicalTreeHelper.cs
- HttpResponse.cs
- TdsEnums.cs
- ErrorRuntimeConfig.cs
- ImageMap.cs
- DictionaryContent.cs
- Geometry.cs
- Double.cs
- PreservationFileReader.cs
- NamedPermissionSet.cs
- PropertyTabChangedEvent.cs
- TreeViewImageKeyConverter.cs
- ConnectionManagementSection.cs
- TextEncodedRawTextWriter.cs
- SpellCheck.cs
- Manipulation.cs
- SessionStateUtil.cs
- validationstate.cs
- Ops.cs
- Classification.cs
- Vector3dCollection.cs
- FilterQuery.cs
- TaiwanCalendar.cs
- Stack.cs
- HitTestDrawingContextWalker.cs
- DocumentXPathNavigator.cs
- XmlFormatWriterGenerator.cs
- ValidatorCompatibilityHelper.cs
- BitmapDownload.cs
- Delegate.cs
- NativeMethods.cs
- RepeatButton.cs
- GeometryCollection.cs
- X509Certificate2Collection.cs
- RotationValidation.cs
- QilValidationVisitor.cs
- LocalizableAttribute.cs
- ELinqQueryState.cs
- XamlSerializationHelper.cs
- SecurityContextSecurityTokenResolver.cs
- Point3DKeyFrameCollection.cs
- Native.cs
- HitTestFilterBehavior.cs