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
- XmlElement.cs
- LayoutUtils.cs
- ChannelManager.cs
- XmlSchemaProviderAttribute.cs
- SelectionGlyphBase.cs
- Thickness.cs
- WindowsServiceCredential.cs
- QilPatternVisitor.cs
- HttpServerVarsCollection.cs
- EncodingNLS.cs
- StyleSheetRefUrlEditor.cs
- SymbolEqualComparer.cs
- XmlWriterTraceListener.cs
- ReflectionUtil.cs
- DocumentEventArgs.cs
- SqlDataSource.cs
- RelatedCurrencyManager.cs
- XmlTextReaderImpl.cs
- DiagnosticSection.cs
- OciLobLocator.cs
- TextRange.cs
- VirtualPathUtility.cs
- ComponentDispatcher.cs
- dataobject.cs
- SQLDateTimeStorage.cs
- DesignerTextBoxAdapter.cs
- QuaternionKeyFrameCollection.cs
- DetailsViewModeEventArgs.cs
- TeredoHelper.cs
- DecoderFallback.cs
- ConfigurationManagerHelper.cs
- OutputCacheSettingsSection.cs
- MenuStrip.cs
- XmlSchemaIdentityConstraint.cs
- XmlAnyElementAttributes.cs
- XmlName.cs
- PtsHost.cs
- XsdDataContractExporter.cs
- DataGrid.cs
- SurrogateSelector.cs
- BackoffTimeoutHelper.cs
- SystemWebCachingSectionGroup.cs
- RowParagraph.cs
- EntryWrittenEventArgs.cs
- XmlSchemaSubstitutionGroup.cs
- Utility.cs
- ResponseStream.cs
- NumericUpDownAcceleration.cs
- DecodeHelper.cs
- IndentedTextWriter.cs
- ObjectItemCollectionAssemblyCacheEntry.cs
- DocobjHost.cs
- MultitargetingHelpers.cs
- OutputWindow.cs
- KeyGestureValueSerializer.cs
- FormCollection.cs
- Panel.cs
- ToggleButton.cs
- DbConnectionClosed.cs
- ManagementBaseObject.cs
- RegexCompiler.cs
- mactripleDES.cs
- QuerySetOp.cs
- AbstractSvcMapFileLoader.cs
- LogArchiveSnapshot.cs
- SerialPinChanges.cs
- oledbmetadatacolumnnames.cs
- MemberHolder.cs
- ResourceWriter.cs
- QueryableDataSourceEditData.cs
- DocumentViewer.cs
- BookmarkResumptionRecord.cs
- SystemShuttingDownException.cs
- codemethodreferenceexpression.cs
- Bold.cs
- TextBlock.cs
- TreeNodeClickEventArgs.cs
- ReachPrintTicketSerializer.cs
- CustomWebEventKey.cs
- Html32TextWriter.cs
- SqlFactory.cs
- DataGridViewCellLinkedList.cs
- BooleanToSelectiveScrollingOrientationConverter.cs
- PointAnimationUsingPath.cs
- ToolboxCategory.cs
- CryptoApi.cs
- basecomparevalidator.cs
- MultiByteCodec.cs
- RowUpdatedEventArgs.cs
- HandleExceptionArgs.cs
- StrokeCollectionConverter.cs
- ScaleTransform3D.cs
- OleDbReferenceCollection.cs
- SoapRpcServiceAttribute.cs
- NetStream.cs
- DesignerSerializationOptionsAttribute.cs
- SystemMulticastIPAddressInformation.cs
- MatrixStack.cs
- SessionStateUtil.cs
- ConfigXmlSignificantWhitespace.cs