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
- OLEDB_Util.cs
- XmlBindingWorker.cs
- Cursor.cs
- ConsumerConnectionPointCollection.cs
- ListViewCancelEventArgs.cs
- Cursors.cs
- elementinformation.cs
- FolderNameEditor.cs
- OleStrCAMarshaler.cs
- XmlNamedNodeMap.cs
- SoapElementAttribute.cs
- CompatibleIComparer.cs
- ApplicationSettingsBase.cs
- diagnosticsswitches.cs
- RecipientInfo.cs
- BitmapEffect.cs
- TableSectionStyle.cs
- ControlCachePolicy.cs
- UnionExpr.cs
- TextOutput.cs
- SoapFormatter.cs
- shaper.cs
- Rectangle.cs
- RemotingConfiguration.cs
- Comparer.cs
- UpdateExpressionVisitor.cs
- XmlLanguageConverter.cs
- ObjectCacheSettings.cs
- X509SecurityToken.cs
- ResourceExpression.cs
- DigestComparer.cs
- SimpleType.cs
- MaxMessageSizeStream.cs
- ComponentEditorPage.cs
- ClientSettingsStore.cs
- SspiHelper.cs
- _LocalDataStoreMgr.cs
- XmlSchemaSubstitutionGroup.cs
- webproxy.cs
- ArgumentValidation.cs
- Bezier.cs
- InputLanguage.cs
- PropertyNames.cs
- ComponentEditorPage.cs
- EntityCommand.cs
- DynamicPropertyHolder.cs
- DataSourceHelper.cs
- XmlSchemaAttribute.cs
- XomlCompiler.cs
- Subtree.cs
- CellParagraph.cs
- Sql8ConformanceChecker.cs
- NameScopePropertyAttribute.cs
- UserControlParser.cs
- EventSchemaTraceListener.cs
- DataSysAttribute.cs
- FreeFormPanel.cs
- GridViewDeleteEventArgs.cs
- BridgeDataReader.cs
- DecoderNLS.cs
- WebPartCollection.cs
- InstanceHandle.cs
- SizeChangedEventArgs.cs
- DataContractSerializerServiceBehavior.cs
- ObjectDataSourceEventArgs.cs
- AdornerLayer.cs
- CodeMethodReturnStatement.cs
- UseLicense.cs
- OptimizerPatterns.cs
- KeyFrames.cs
- Storyboard.cs
- CompoundFileStorageReference.cs
- CqlLexer.cs
- ButtonRenderer.cs
- ClientBuildManagerTypeDescriptionProviderBridge.cs
- CachedTypeface.cs
- MediaTimeline.cs
- PackageStore.cs
- ToolStripItemRenderEventArgs.cs
- Section.cs
- OleDbReferenceCollection.cs
- ProgramPublisher.cs
- HttpCacheVary.cs
- BoundField.cs
- BindingManagerDataErrorEventArgs.cs
- DatagridviewDisplayedBandsData.cs
- EventBuilder.cs
- FileStream.cs
- DataListItemCollection.cs
- DataServiceResponse.cs
- WebPartDisplayModeCancelEventArgs.cs
- ComPlusDiagnosticTraceRecords.cs
- InheritanceContextChangedEventManager.cs
- BulletedList.cs
- ModifiableIteratorCollection.cs
- ConfigXmlSignificantWhitespace.cs
- CodeCatchClauseCollection.cs
- NaturalLanguageHyphenator.cs
- TextEffect.cs
- ParagraphResult.cs