Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / xsp / System / Web / UI / WebControls / VerticalAlignConverter.cs / 1 / VerticalAlignConverter.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 VerticalAlignConverter : EnumConverter { static string[] stringValues = new String[(int) VerticalAlign.Bottom + 1]; static VerticalAlignConverter () { stringValues[(int) VerticalAlign.NotSet] = "NotSet"; stringValues[(int) VerticalAlign.Top] = "Top"; stringValues[(int) VerticalAlign.Middle] = "Middle"; stringValues[(int) VerticalAlign.Bottom] = "Bottom"; } // 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 VerticalAlignConverter () : base(typeof(VerticalAlign)) {} 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 VerticalAlign.NotSet; switch (textValue) { case "NotSet": return VerticalAlign.NotSet; case "Top": return VerticalAlign.Top; case "Middle": return VerticalAlign.Middle; case "Bottom": return VerticalAlign.Bottom; } } 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)VerticalAlign.Bottom)) { return stringValues[(int) value]; } return base.ConvertTo(context, culture, value, destinationType); } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CollectionBuilder.cs
- RelatedImageListAttribute.cs
- TextTreeTextNode.cs
- ObjectPersistData.cs
- KnownTypeHelper.cs
- SubtreeProcessor.cs
- DrawingGroup.cs
- COM2PropertyDescriptor.cs
- AccessControlEntry.cs
- SendActivityEventArgs.cs
- SecurityUtils.cs
- EntityDataSourceWrapper.cs
- OracleConnectionFactory.cs
- StrongNameKeyPair.cs
- ListManagerBindingsCollection.cs
- DataGridBoolColumn.cs
- HatchBrush.cs
- HttpRuntime.cs
- SchemaTableOptionalColumn.cs
- ObjectManager.cs
- SuppressIldasmAttribute.cs
- SiteMapNode.cs
- Activity.cs
- HandledMouseEvent.cs
- OrderedDictionaryStateHelper.cs
- SQLByte.cs
- PersonalizableTypeEntry.cs
- ReadOnlyHierarchicalDataSourceView.cs
- FrameworkPropertyMetadata.cs
- Triplet.cs
- MenuStrip.cs
- MulticastDelegate.cs
- NotImplementedException.cs
- ObjectStateManager.cs
- AppSecurityManager.cs
- BitmapMetadataEnumerator.cs
- XmlSchemaComplexType.cs
- ClientScriptManager.cs
- DataGridViewTopRowAccessibleObject.cs
- NamedPipeChannelListener.cs
- CodePageUtils.cs
- RegistryConfigurationProvider.cs
- HitTestFilterBehavior.cs
- XmlSerializerSection.cs
- PipelineModuleStepContainer.cs
- DelayedRegex.cs
- GridViewUpdateEventArgs.cs
- CodeParameterDeclarationExpressionCollection.cs
- TrackingStringDictionary.cs
- HtmlContainerControl.cs
- GroupQuery.cs
- Slider.cs
- WebPartEditorOkVerb.cs
- CriticalFinalizerObject.cs
- SynchronousChannelMergeEnumerator.cs
- WorkflowTransactionOptions.cs
- InputScopeAttribute.cs
- CalendarAutomationPeer.cs
- MetadataItemEmitter.cs
- FolderBrowserDialog.cs
- _SafeNetHandles.cs
- AsyncInvokeContext.cs
- XmlNode.cs
- TextTreeDeleteContentUndoUnit.cs
- OrthographicCamera.cs
- LinkArea.cs
- Freezable.cs
- FormsIdentity.cs
- ClassImporter.cs
- SystemException.cs
- ComplexPropertyEntry.cs
- PasswordTextContainer.cs
- BamlResourceSerializer.cs
- PrePrepareMethodAttribute.cs
- BamlBinaryReader.cs
- WebBrowserProgressChangedEventHandler.cs
- EntityDataSourceViewSchema.cs
- GridViewCommandEventArgs.cs
- PathFigureCollection.cs
- ReadOnlyHierarchicalDataSource.cs
- OleDbRowUpdatedEvent.cs
- DataGridItem.cs
- WsatTransactionHeader.cs
- serverconfig.cs
- BindToObject.cs
- BasePropertyDescriptor.cs
- MissingManifestResourceException.cs
- IItemContainerGenerator.cs
- MonikerSyntaxException.cs
- TextElementCollectionHelper.cs
- ImageDrawing.cs
- SortedDictionary.cs
- OleDbConnectionFactory.cs
- WindowsTitleBar.cs
- IOThreadScheduler.cs
- ObjectQueryExecutionPlan.cs
- BindingContext.cs
- WebPartZone.cs
- FlowLayoutPanel.cs
- ProgramPublisher.cs