Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / UI / WebControls / VerticalAlignConverter.cs / 1305376 / 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); } } } // 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 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); } } } // 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
- NullableBoolConverter.cs
- EncodingInfo.cs
- TextViewSelectionProcessor.cs
- SiteMapSection.cs
- XmlSchemaElement.cs
- InstanceCollisionException.cs
- PageCatalogPart.cs
- FunctionDetailsReader.cs
- cache.cs
- DesignerAttribute.cs
- ObjectRef.cs
- DocumentPage.cs
- AuthorizationSection.cs
- MultiDataTrigger.cs
- LinqDataSource.cs
- EasingQuaternionKeyFrame.cs
- InheritanceAttribute.cs
- ClientTargetCollection.cs
- DataListItemEventArgs.cs
- SystemResourceHost.cs
- DataServiceRequestOfT.cs
- FixedSOMPageElement.cs
- CompilerResults.cs
- XPathNavigator.cs
- HierarchicalDataBoundControlAdapter.cs
- ErrorWebPart.cs
- BufferBuilder.cs
- RSAPKCS1SignatureDeformatter.cs
- ConstantCheck.cs
- AccessibleObject.cs
- Misc.cs
- SqlDataSourceCustomCommandEditor.cs
- AmbientLight.cs
- SerializableTypeCodeDomSerializer.cs
- ContextProperty.cs
- TransformCryptoHandle.cs
- NavigatingCancelEventArgs.cs
- MultilineStringEditor.cs
- HMACSHA384.cs
- PrintingPermission.cs
- MdiWindowListStrip.cs
- CatalogPartChrome.cs
- XamlSerializerUtil.cs
- ServiceOperationParameter.cs
- DataGridBoolColumn.cs
- TreeNodeEventArgs.cs
- ObjectContext.cs
- WebRequestModulesSection.cs
- RepeatButtonAutomationPeer.cs
- RuntimeConfig.cs
- TargetConverter.cs
- CachingParameterInspector.cs
- ContainerParagraph.cs
- ButtonChrome.cs
- TypeUnloadedException.cs
- JoinCqlBlock.cs
- Latin1Encoding.cs
- CanonicalFormWriter.cs
- basenumberconverter.cs
- ElementAction.cs
- ListParagraph.cs
- DataGridViewColumnCollection.cs
- X509CertificateTrustedIssuerElement.cs
- AsymmetricKeyExchangeFormatter.cs
- RectangleHotSpot.cs
- ToolStripSystemRenderer.cs
- HttpServerVarsCollection.cs
- CmsUtils.cs
- HostingEnvironmentException.cs
- Renderer.cs
- SpellerError.cs
- HtmlButton.cs
- LogStore.cs
- DynamicILGenerator.cs
- SHA384.cs
- TableAutomationPeer.cs
- NameSpaceExtractor.cs
- ListViewItemMouseHoverEvent.cs
- CopyAction.cs
- Control.cs
- securestring.cs
- ListViewContainer.cs
- PrivateFontCollection.cs
- StorageTypeMapping.cs
- SqlBuffer.cs
- ToolZone.cs
- BinaryUtilClasses.cs
- XsltException.cs
- BoundsDrawingContextWalker.cs
- PrePrepareMethodAttribute.cs
- GetWinFXPath.cs
- MappingSource.cs
- XamlTypeMapper.cs
- DataDocumentXPathNavigator.cs
- Faults.cs
- listitem.cs
- XPathParser.cs
- _FixedSizeReader.cs
- Vector3DKeyFrameCollection.cs
- DrawingImage.cs