Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / 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); } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TraceProvider.cs
- CompiledAction.cs
- MutexSecurity.cs
- CodeDomSerializerException.cs
- Compiler.cs
- GridViewColumn.cs
- KeySpline.cs
- RuntimeHelpers.cs
- DoubleConverter.cs
- XmlnsCompatibleWithAttribute.cs
- MemberHolder.cs
- OpenTypeMethods.cs
- Pair.cs
- FtpRequestCacheValidator.cs
- Int32Collection.cs
- RSAPKCS1SignatureFormatter.cs
- UnsafeNativeMethods.cs
- bidPrivateBase.cs
- ProfilePropertySettings.cs
- CodeMemberEvent.cs
- LongCountAggregationOperator.cs
- SendMailErrorEventArgs.cs
- MappingException.cs
- SendingRequestEventArgs.cs
- CompilerParameters.cs
- MiniCustomAttributeInfo.cs
- Certificate.cs
- CodeSnippetExpression.cs
- TypeConverters.cs
- DataRecord.cs
- Mouse.cs
- SafeNativeMethodsCLR.cs
- LabelEditEvent.cs
- ProxyGenerationError.cs
- OutOfMemoryException.cs
- RankException.cs
- OrderByQueryOptionExpression.cs
- ObjectIDGenerator.cs
- HtmlControl.cs
- VisualStyleElement.cs
- ExpressionCopier.cs
- CatalogPartChrome.cs
- StreamInfo.cs
- NativeMethods.cs
- DataSourceHelper.cs
- SystemNetworkInterface.cs
- EntityTypeEmitter.cs
- FacetValueContainer.cs
- UnsafeNativeMethods.cs
- Font.cs
- Model3DCollection.cs
- ParserHooks.cs
- MSG.cs
- MasterPage.cs
- XamlTreeBuilder.cs
- TextEditorSelection.cs
- WebPartsPersonalization.cs
- ItemMap.cs
- DbConnectionPoolIdentity.cs
- InheritablePropertyChangeInfo.cs
- AcceptorSessionSymmetricTransportSecurityProtocol.cs
- HttpBufferlessInputStream.cs
- EntityDataSource.cs
- MaskedTextProvider.cs
- MethodAccessException.cs
- ListView.cs
- PathParser.cs
- SafeProcessHandle.cs
- CodeAttributeArgumentCollection.cs
- FormsAuthenticationUserCollection.cs
- WindowPattern.cs
- DbDataReader.cs
- EdmItemCollection.OcAssemblyCache.cs
- SafeNativeMethods.cs
- TextElementCollection.cs
- SafeNativeMethods.cs
- FormParameter.cs
- SafeRightsManagementEnvironmentHandle.cs
- EventQueueState.cs
- ThemeDirectoryCompiler.cs
- ItemList.cs
- PermissionSet.cs
- DiscoveryClientDocuments.cs
- LexicalChunk.cs
- HtmlAnchor.cs
- GenericEnumConverter.cs
- SQLBinaryStorage.cs
- _Events.cs
- _AcceptOverlappedAsyncResult.cs
- CompModSwitches.cs
- CodeVariableDeclarationStatement.cs
- WebScriptServiceHostFactory.cs
- QilInvokeLateBound.cs
- CrossAppDomainChannel.cs
- EntityDataSourceMemberPath.cs
- SHA1CryptoServiceProvider.cs
- Comparer.cs
- StorageTypeMapping.cs
- DataGridClipboardCellContent.cs
- JournalNavigationScope.cs