Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- ThemeDirectoryCompiler.cs
- DataTemplateKey.cs
- CodeTypeReference.cs
- DbConnectionPoolOptions.cs
- Stack.cs
- ThreadWorkerController.cs
- Comparer.cs
- StringUtil.cs
- MetadataException.cs
- RawStylusActions.cs
- _IPv6Address.cs
- CharacterMetricsDictionary.cs
- IdentityHolder.cs
- Filter.cs
- RuntimeHandles.cs
- XmlTypeAttribute.cs
- HtmlTitle.cs
- VBCodeProvider.cs
- RegexMatchCollection.cs
- RectangleGeometry.cs
- ListBindingHelper.cs
- UnaryNode.cs
- HMACSHA1.cs
- UdpTransportBindingElement.cs
- SubMenuStyleCollection.cs
- GreenMethods.cs
- Compiler.cs
- BaseDataListComponentEditor.cs
- ProvidersHelper.cs
- ListComponentEditorPage.cs
- ClientConfigPaths.cs
- GroupDescription.cs
- CompositeFontInfo.cs
- DataColumn.cs
- WebPartEditorApplyVerb.cs
- UnmanagedBitmapWrapper.cs
- PropertyTabChangedEvent.cs
- IxmlLineInfo.cs
- PostBackTrigger.cs
- AssociativeAggregationOperator.cs
- CompositionCommandSet.cs
- ComAdminWrapper.cs
- EntityDataSourceState.cs
- Exception.cs
- SubclassTypeValidator.cs
- MetadataFile.cs
- AnimationClock.cs
- WebUtility.cs
- ObsoleteAttribute.cs
- IIS7UserPrincipal.cs
- RNGCryptoServiceProvider.cs
- MissingFieldException.cs
- XmlDataSourceView.cs
- ProgressBarRenderer.cs
- ListViewCancelEventArgs.cs
- MetadataPropertyCollection.cs
- CheckBoxBaseAdapter.cs
- ExceptionValidationRule.cs
- RuleSettingsCollection.cs
- AxDesigner.cs
- LinqDataSourceContextEventArgs.cs
- CreateUserErrorEventArgs.cs
- LocalizabilityAttribute.cs
- KeyboardDevice.cs
- RequestBringIntoViewEventArgs.cs
- Pkcs7Recipient.cs
- XmlSchemaObjectCollection.cs
- RepeaterDataBoundAdapter.cs
- BitmapInitialize.cs
- DataSetUtil.cs
- InvalidPropValue.cs
- DataGridViewRowErrorTextNeededEventArgs.cs
- ReverseInheritProperty.cs
- DrawingDrawingContext.cs
- TripleDESCryptoServiceProvider.cs
- Rules.cs
- XmlEnumAttribute.cs
- PropertyRecord.cs
- Root.cs
- ResourceWriter.cs
- ReflectionPermission.cs
- ProxyFragment.cs
- MLangCodePageEncoding.cs
- MessageQueue.cs
- ContentElement.cs
- RegisteredScript.cs
- RectAnimation.cs
- OrderedDictionaryStateHelper.cs
- EnterpriseServicesHelper.cs
- MultiBinding.cs
- AutomationPatternInfo.cs
- ByteViewer.cs
- IdentifierCollection.cs
- XmlSchemaImporter.cs
- ListBoxItem.cs
- PaintEvent.cs
- WinEventHandler.cs
- BaseInfoTable.cs
- CollectionViewSource.cs
- RegexWorker.cs