Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / 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);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
//
// 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- GridViewRowEventArgs.cs
- DataGridViewUtilities.cs
- WebPart.cs
- CompressStream.cs
- MachineSettingsSection.cs
- XslAst.cs
- TitleStyle.cs
- SystemIPv4InterfaceProperties.cs
- RequestDescription.cs
- EditBehavior.cs
- CallbackHandler.cs
- ObjectHandle.cs
- QuaternionAnimationUsingKeyFrames.cs
- ReceiveSecurityHeaderElementManager.cs
- TraceSection.cs
- GregorianCalendar.cs
- IntPtr.cs
- MethodExpr.cs
- JsonQueryStringConverter.cs
- SendMailErrorEventArgs.cs
- Cloud.cs
- NamedPermissionSet.cs
- TableLayoutStyleCollection.cs
- DropTarget.cs
- XmlMemberMapping.cs
- Clock.cs
- VirtualPath.cs
- DesignerCategoryAttribute.cs
- Environment.cs
- ExeContext.cs
- DocumentCollection.cs
- XhtmlBasicObjectListAdapter.cs
- ObjectParameter.cs
- WindowsProgressbar.cs
- OracleDataReader.cs
- DataKey.cs
- Binding.cs
- FileSystemEnumerable.cs
- XmlNamespaceDeclarationsAttribute.cs
- BuildProvider.cs
- OracleDateTime.cs
- ScrollPattern.cs
- ToolStripPanelRow.cs
- RequestQueue.cs
- NamespaceQuery.cs
- ToolStripCollectionEditor.cs
- DateTimeValueSerializer.cs
- SplashScreen.cs
- TrustManagerPromptUI.cs
- JpegBitmapEncoder.cs
- FactoryMaker.cs
- WindowsUserNameSecurityTokenAuthenticator.cs
- Deflater.cs
- Material.cs
- QueryableDataSource.cs
- PeerTransportElement.cs
- BitmapImage.cs
- RuntimeHandles.cs
- ColumnClickEvent.cs
- WebPartUserCapability.cs
- URLEditor.cs
- Decoder.cs
- UnionExpr.cs
- DateTimeFormatInfo.cs
- InputReport.cs
- ProgramPublisher.cs
- ButtonPopupAdapter.cs
- ClientRuntimeConfig.cs
- XmlArrayItemAttributes.cs
- SqlClientWrapperSmiStream.cs
- Container.cs
- SymbolEqualComparer.cs
- MouseCaptureWithinProperty.cs
- PriorityBinding.cs
- HelpEvent.cs
- SqlUserDefinedTypeAttribute.cs
- ControlEvent.cs
- SequentialOutput.cs
- BaseResourcesBuildProvider.cs
- EncoderNLS.cs
- DependencyPropertyValueSerializer.cs
- WriteableBitmap.cs
- HtmlElementCollection.cs
- DataObjectFieldAttribute.cs
- ThreadExceptionEvent.cs
- PowerModeChangedEventArgs.cs
- IsolatedStoragePermission.cs
- ImageIndexConverter.cs
- XPathParser.cs
- FrameSecurityDescriptor.cs
- GeneralTransform.cs
- FlowPosition.cs
- TextFragmentEngine.cs
- XmlTextAttribute.cs
- LineVisual.cs
- HttpApplicationStateBase.cs
- ArrayConverter.cs
- TextTreeUndo.cs
- GenericsInstances.cs
- HyperLinkStyle.cs