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
- SelectionChangedEventArgs.cs
- MatrixTransform.cs
- GridItem.cs
- Int64AnimationBase.cs
- ZipIOExtraField.cs
- IntegerCollectionEditor.cs
- TreeView.cs
- PointLightBase.cs
- PlainXmlWriter.cs
- MarkupProperty.cs
- ToolStripSeparator.cs
- XPathNavigatorException.cs
- sqlinternaltransaction.cs
- TagNameToTypeMapper.cs
- MessageBox.cs
- DocumentXPathNavigator.cs
- HttpCacheVary.cs
- Command.cs
- ObjectPropertyMapping.cs
- ThreadInterruptedException.cs
- _ShellExpression.cs
- TabPanel.cs
- HyperLinkColumn.cs
- BigInt.cs
- QilSortKey.cs
- TextTreeObjectNode.cs
- ProtectedConfigurationSection.cs
- VisualBrush.cs
- XmlTypeAttribute.cs
- Context.cs
- XmlSchemaAnyAttribute.cs
- Encoder.cs
- ShapeTypeface.cs
- SqlRewriteScalarSubqueries.cs
- ConfigurationStrings.cs
- tooltip.cs
- DataGridViewTextBoxEditingControl.cs
- TextEditorTyping.cs
- RoutedEventArgs.cs
- Bitmap.cs
- _NetRes.cs
- MeasureData.cs
- MimeObjectFactory.cs
- PageCatalogPart.cs
- ADRoleFactory.cs
- RemoteWebConfigurationHostServer.cs
- QilName.cs
- PerformanceCounter.cs
- StaticSiteMapProvider.cs
- TranslateTransform3D.cs
- OutputCache.cs
- CreateUserWizardStep.cs
- PropertyGrid.cs
- XmlNodeList.cs
- XmlSerializationGeneratedCode.cs
- ListViewGroupItemCollection.cs
- HwndSourceParameters.cs
- FixedDocument.cs
- MasterPageCodeDomTreeGenerator.cs
- DataGridAddNewRow.cs
- AddToCollection.cs
- cache.cs
- LoginUtil.cs
- HtmlCalendarAdapter.cs
- RuntimeTrackingProfile.cs
- Misc.cs
- XpsSerializationManagerAsync.cs
- GPRECT.cs
- WebPartConnectionsDisconnectVerb.cs
- EntityDescriptor.cs
- Permission.cs
- DataFormats.cs
- XXXOnTypeBuilderInstantiation.cs
- SchemaNames.cs
- PlainXmlSerializer.cs
- EventDescriptorCollection.cs
- ComplexObject.cs
- CodeTypeParameter.cs
- PipelineComponent.cs
- LinkDesigner.cs
- SharedStatics.cs
- WebConfigurationManager.cs
- GregorianCalendar.cs
- MultiSelector.cs
- RegexWriter.cs
- TemplateKeyConverter.cs
- RunClient.cs
- ProbeRequestResponseAsyncResult.cs
- CharStorage.cs
- MarginCollapsingState.cs
- DBProviderConfigurationHandler.cs
- EntityContainerRelationshipSet.cs
- SemanticValue.cs
- TypeInitializationException.cs
- EventMappingSettings.cs
- DataServiceRequestException.cs
- XmlSchemaInfo.cs
- ListDictionaryInternal.cs
- MimeObjectFactory.cs
- ComplexBindingPropertiesAttribute.cs