Code:
/ FX-1434 / FX-1434 / 1.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
- HttpResponse.cs
- CompilationPass2TaskInternal.cs
- PeerPresenceInfo.cs
- CodeValidator.cs
- XmlNamespaceManager.cs
- _AuthenticationState.cs
- ShaderEffect.cs
- ExtendedProtectionPolicyTypeConverter.cs
- BaseCollection.cs
- ToolStripComboBox.cs
- Timeline.cs
- StandardCommands.cs
- DataKeyCollection.cs
- TextEffect.cs
- SerializableAttribute.cs
- iisPickupDirectory.cs
- ControlValuePropertyAttribute.cs
- SqlRecordBuffer.cs
- WindowsScrollBarBits.cs
- ClientTargetSection.cs
- Speller.cs
- SchemaTableOptionalColumn.cs
- Panel.cs
- ToolStripPanelCell.cs
- Activity.cs
- X509LogoTypeExtension.cs
- EventProviderWriter.cs
- Registration.cs
- SqlConnection.cs
- _SSPISessionCache.cs
- BitmapEffectInputConnector.cs
- MarkupCompilePass2.cs
- CustomErrorsSection.cs
- FlowDocumentScrollViewerAutomationPeer.cs
- PropertyDescriptorGridEntry.cs
- ValidationHelper.cs
- WebServiceMethodData.cs
- ObfuscateAssemblyAttribute.cs
- ItemsPanelTemplate.cs
- DirtyTextRange.cs
- Variable.cs
- CallTemplateAction.cs
- DbParameterCollection.cs
- ConditionedDesigner.cs
- ProxyWebPartManager.cs
- EnumerableRowCollectionExtensions.cs
- Internal.cs
- MarkupProperty.cs
- ContractsBCL.cs
- SignatureHelper.cs
- _TransmitFileOverlappedAsyncResult.cs
- ProcessThreadCollection.cs
- PageClientProxyGenerator.cs
- RSAOAEPKeyExchangeFormatter.cs
- messageonlyhwndwrapper.cs
- ItemCheckEvent.cs
- SchemaDeclBase.cs
- TrackingServices.cs
- RenderData.cs
- TableLayout.cs
- WorkflowClientDeliverMessageWrapper.cs
- AuthenticationServiceManager.cs
- SqlGenericUtil.cs
- ToolStripSplitButton.cs
- TextSegment.cs
- DataTable.cs
- SqlDataSourceConfigureSortForm.cs
- LockedHandleGlyph.cs
- PageThemeParser.cs
- WebPartConnectionsCancelEventArgs.cs
- ObjectSelectorEditor.cs
- FacetValues.cs
- DbConnectionClosed.cs
- DaylightTime.cs
- AssociationType.cs
- DataSourceXmlAttributeAttribute.cs
- BamlStream.cs
- ElementMarkupObject.cs
- NamespaceList.cs
- PermissionSet.cs
- Margins.cs
- QueuePathDialog.cs
- ArrangedElement.cs
- SchemaHelper.cs
- RelationalExpressions.cs
- ExpressionPrefixAttribute.cs
- UpdateProgress.cs
- QilExpression.cs
- SchemaNames.cs
- StatusStrip.cs
- GridViewCellAutomationPeer.cs
- MarginsConverter.cs
- ProtectedConfigurationSection.cs
- LocalizationParserHooks.cs
- SqlPersonalizationProvider.cs
- BaseTreeIterator.cs
- EventLogPermissionAttribute.cs
- DbProviderConfigurationHandler.cs
- UnicodeEncoding.cs
- ComponentDispatcherThread.cs