Code:
/ 4.0 / 4.0 / 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. //------------------------------------------------------------------------------ //// 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
- ISO2022Encoding.cs
- MatrixKeyFrameCollection.cs
- RangeValuePattern.cs
- QueryConverter.cs
- TdsParameterSetter.cs
- _SpnDictionary.cs
- XamlToRtfParser.cs
- FormatException.cs
- ListViewInsertedEventArgs.cs
- WebBrowsableAttribute.cs
- JsonStringDataContract.cs
- KeyBinding.cs
- CryptoProvider.cs
- TranslateTransform3D.cs
- ToolBar.cs
- DataGridViewHitTestInfo.cs
- Int32CAMarshaler.cs
- ActiveDocumentEvent.cs
- XmlArrayItemAttribute.cs
- Knowncolors.cs
- ProcessActivityTreeOptions.cs
- PackageRelationshipCollection.cs
- SmiContextFactory.cs
- XMLUtil.cs
- HttpListenerTimeoutManager.cs
- ReplacementText.cs
- ThreadStateException.cs
- LingerOption.cs
- SingleConverter.cs
- GenericPrincipal.cs
- QilCloneVisitor.cs
- AppSettingsReader.cs
- StrokeDescriptor.cs
- Bitmap.cs
- IApplicationTrustManager.cs
- DbgCompiler.cs
- ColorConvertedBitmap.cs
- OptimisticConcurrencyException.cs
- RectangleF.cs
- CornerRadiusConverter.cs
- NativeWindow.cs
- DataViewManagerListItemTypeDescriptor.cs
- StringFunctions.cs
- TextBoxRenderer.cs
- MsmqBindingFilter.cs
- LoginView.cs
- XamlDebuggerXmlReader.cs
- LocatorPart.cs
- DBConnectionString.cs
- PageCatalogPart.cs
- SchemaTableOptionalColumn.cs
- QilStrConcatenator.cs
- GridLength.cs
- AlphaSortedEnumConverter.cs
- DataGridRowDetailsEventArgs.cs
- SmiMetaData.cs
- CodeBinaryOperatorExpression.cs
- SHA256.cs
- XamlSerializerUtil.cs
- SystemColors.cs
- PrintController.cs
- IndentTextWriter.cs
- DocumentXmlWriter.cs
- HandlerFactoryWrapper.cs
- HtmlToClrEventProxy.cs
- AuthStoreRoleProvider.cs
- ScriptingJsonSerializationSection.cs
- StreamWithDictionary.cs
- _BasicClient.cs
- SafeUserTokenHandle.cs
- InvalidCastException.cs
- WmlMobileTextWriter.cs
- Pen.cs
- ManifestBasedResourceGroveler.cs
- ParseHttpDate.cs
- CodeAttributeDeclarationCollection.cs
- ProgressPage.cs
- HeaderPanel.cs
- Helpers.cs
- SQlBooleanStorage.cs
- _WinHttpWebProxyDataBuilder.cs
- PrintPreviewDialog.cs
- _LoggingObject.cs
- LambdaCompiler.Address.cs
- StringAnimationBase.cs
- SQLConvert.cs
- DBSchemaTable.cs
- AsyncContentLoadedEventArgs.cs
- ObjectParameterCollection.cs
- ComboBoxAutomationPeer.cs
- Errors.cs
- HttpContextServiceHost.cs
- XmlCharType.cs
- Parameter.cs
- FormatSettings.cs
- RectAnimationUsingKeyFrames.cs
- GenericAuthenticationEventArgs.cs
- RootBuilder.cs
- FixedDocumentSequencePaginator.cs
- httpserverutility.cs