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
- ClientTargetSection.cs
- CaseInsensitiveComparer.cs
- RectValueSerializer.cs
- IgnoreSectionHandler.cs
- TableLayoutStyle.cs
- PageFunction.cs
- DataGridAutomationPeer.cs
- ScriptControlDescriptor.cs
- SQLCharsStorage.cs
- ActivitiesCollection.cs
- CompilerError.cs
- ResourcePermissionBaseEntry.cs
- QuotedStringWriteStateInfo.cs
- DbModificationClause.cs
- XmlEntityReference.cs
- Point3DCollectionValueSerializer.cs
- SchemaTableColumn.cs
- ObjectResult.cs
- QueryCacheKey.cs
- Single.cs
- LoadedOrUnloadedOperation.cs
- CodeConditionStatement.cs
- LayoutInformation.cs
- NavigateUrlConverter.cs
- ContentElement.cs
- RectConverter.cs
- PartialList.cs
- EntityDataSourceView.cs
- Set.cs
- PropertyDescriptors.cs
- ButtonFieldBase.cs
- TransformationRules.cs
- AesCryptoServiceProvider.cs
- DocumentApplicationJournalEntry.cs
- ConfigurationPermission.cs
- MemberMaps.cs
- UrlPropertyAttribute.cs
- IgnorePropertiesAttribute.cs
- SafeArrayTypeMismatchException.cs
- UserControl.cs
- ToolStripArrowRenderEventArgs.cs
- HtmlPanelAdapter.cs
- FileDialog_Vista.cs
- FragmentNavigationEventArgs.cs
- TypeTypeConverter.cs
- SrgsSubset.cs
- AbstractExpressions.cs
- HandlerBase.cs
- XsdDateTime.cs
- LineSegment.cs
- SessionStateItemCollection.cs
- SettingsPropertyValue.cs
- ManagedIStream.cs
- TextBox.cs
- ChtmlFormAdapter.cs
- Point3D.cs
- ListViewCancelEventArgs.cs
- DateTimeFormatInfo.cs
- HtmlInputHidden.cs
- MetadataSerializer.cs
- SaveFileDialog.cs
- TreeViewAutomationPeer.cs
- PropertyChangedEventArgs.cs
- ThreadStateException.cs
- ButtonRenderer.cs
- ClientScriptManagerWrapper.cs
- HandleRef.cs
- Expr.cs
- XmlQueryRuntime.cs
- XmlReflectionMember.cs
- ConfigXmlText.cs
- SoapProtocolImporter.cs
- HierarchicalDataBoundControl.cs
- DBConcurrencyException.cs
- CollectionBase.cs
- Vector3DCollectionValueSerializer.cs
- DragEventArgs.cs
- BulletedListEventArgs.cs
- DbConnectionPool.cs
- Control.cs
- FieldCollectionEditor.cs
- TextLineResult.cs
- TextCollapsingProperties.cs
- TreeView.cs
- TextDpi.cs
- GenericTextProperties.cs
- ArgIterator.cs
- MonthCalendar.cs
- BamlCollectionHolder.cs
- EncryptedKeyIdentifierClause.cs
- MyContact.cs
- KeyEvent.cs
- OpenFileDialog.cs
- MachineSettingsSection.cs
- TraceData.cs
- Calendar.cs
- BuildProviderInstallComponent.cs
- CodeNamespaceCollection.cs
- FileDialogCustomPlacesCollection.cs
- ViewKeyConstraint.cs