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
- DataControlField.cs
- DesignTimeVisibleAttribute.cs
- ServiceOperationParameter.cs
- Hash.cs
- WebPartZone.cs
- XamlVector3DCollectionSerializer.cs
- XpsImage.cs
- Int64KeyFrameCollection.cs
- ClassDataContract.cs
- EventMappingSettingsCollection.cs
- COM2ExtendedUITypeEditor.cs
- SimpleHandlerFactory.cs
- ResourceDictionaryCollection.cs
- HtmlTable.cs
- PrintPreviewDialog.cs
- UncommonField.cs
- RealizationDrawingContextWalker.cs
- RoutedEventValueSerializer.cs
- EncryptedKeyIdentifierClause.cs
- CompositeDataBoundControl.cs
- JournalEntryStack.cs
- EllipseGeometry.cs
- EpmSourceTree.cs
- Asn1IntegerConverter.cs
- SQLRoleProvider.cs
- PackageRelationshipSelector.cs
- MouseGestureConverter.cs
- CodeSubDirectory.cs
- DataListDesigner.cs
- PreviewKeyDownEventArgs.cs
- ComponentCollection.cs
- StyleSelector.cs
- XmlAttributeProperties.cs
- AutoResizedEvent.cs
- ISCIIEncoding.cs
- ProcessHostConfigUtils.cs
- CredentialCache.cs
- _Semaphore.cs
- CodePrimitiveExpression.cs
- JsonDeserializer.cs
- DispatcherHooks.cs
- BaseAddressPrefixFilterElement.cs
- CacheAxisQuery.cs
- ColumnMapVisitor.cs
- WindowsFormsSectionHandler.cs
- DSASignatureDeformatter.cs
- _NativeSSPI.cs
- ObjectHandle.cs
- PageRequestManager.cs
- DefaultSerializationProviderAttribute.cs
- TableDetailsRow.cs
- Pts.cs
- PathNode.cs
- TypeName.cs
- LinqExpressionNormalizer.cs
- SqlBuffer.cs
- ImageList.cs
- NavigationPropertyEmitter.cs
- SafeSecurityHelper.cs
- SafeRightsManagementEnvironmentHandle.cs
- cryptoapiTransform.cs
- MediaEntryAttribute.cs
- FormParameter.cs
- PaperSize.cs
- OleDbParameter.cs
- WindowsListViewItemStartMenu.cs
- HttpFileCollection.cs
- SynchronizedCollection.cs
- ToolBar.cs
- SQLBinaryStorage.cs
- SchemaType.cs
- TraceHandlerErrorFormatter.cs
- SolidColorBrush.cs
- ProtocolReflector.cs
- SiteMapNodeItem.cs
- PartialArray.cs
- ListSortDescriptionCollection.cs
- _SpnDictionary.cs
- TransformerTypeCollection.cs
- TextProperties.cs
- BitmapScalingModeValidation.cs
- XPathSingletonIterator.cs
- ClusterSafeNativeMethods.cs
- StylusPointCollection.cs
- Rules.cs
- NullToBooleanConverter.cs
- UIAgentInitializationException.cs
- Registry.cs
- ScriptingJsonSerializationSection.cs
- WebDescriptionAttribute.cs
- ScriptingRoleServiceSection.cs
- regiisutil.cs
- RelationshipFixer.cs
- XPathAncestorQuery.cs
- PrimarySelectionAdorner.cs
- InvalidPropValue.cs
- DbModificationClause.cs
- ThreadStateException.cs
- XamlStream.cs
- DetailsViewRowCollection.cs