Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / xsp / System / Web / UI / WebControls / FontUnitConverter.cs / 1 / FontUnitConverter.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Reflection;
using System.Security.Permissions;
using System.Web.Util;
///
/// Converts a to and from a specified data type.
///
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class FontUnitConverter : TypeConverter {
private StandardValuesCollection values;
///
/// Determines if the specified data type can be converted to a .
///
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
if (sourceType == typeof(string)) {
return true;
}
else {
return base.CanConvertFrom(context, sourceType);
}
}
///
/// Converts the specified into a .
///
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
if (value == null)
return null;
string stringValue = value as string;
if (stringValue != null) {
string textValue = stringValue.Trim();
if (textValue.Length == 0) {
return FontUnit.Empty;
}
return FontUnit.Parse(textValue, culture);
}
else {
return base.ConvertFrom(context, culture, value);
}
}
///
///
/// Returns a value indicating whether the converter can
/// convert to the specified destination type.
///
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
if ((destinationType == typeof(string)) ||
(destinationType == typeof(InstanceDescriptor))) {
return true;
}
else {
return base.CanConvertTo(context, destinationType);
}
}
///
/// Converts the specified into the specified .
///
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
if (destinationType == typeof(string)) {
if ((value == null) || (((FontUnit)value).Type == FontSize.NotSet))
return String.Empty;
else
return ((FontUnit)value).ToString(culture);
}
else if ((destinationType == typeof(InstanceDescriptor)) && (value != null)) {
FontUnit u = (FontUnit)value;
MemberInfo member = null;
object[] args = null;
if (u.IsEmpty) {
member = typeof(FontUnit).GetField("Empty");
}
else if (u.Type != FontSize.AsUnit) {
string fieldName = null;
switch (u.Type) {
case FontSize.Smaller:
fieldName = "Smaller";
break;
case FontSize.Larger:
fieldName = "Larger";
break;
case FontSize.XXSmall:
fieldName = "XXSmall";
break;
case FontSize.XSmall:
fieldName = "XSmall";
break;
case FontSize.Small:
fieldName = "Small";
break;
case FontSize.Medium:
fieldName = "Medium";
break;
case FontSize.Large:
fieldName = "Large";
break;
case FontSize.XLarge:
fieldName = "XLarge";
break;
case FontSize.XXLarge:
fieldName = "XXLarge";
break;
}
Debug.Assert(fieldName != null, "Invalid FontSize type");
if (fieldName != null) {
member = typeof(FontUnit).GetField(fieldName);
}
}
else {
member = typeof(FontUnit).GetConstructor(new Type[] { typeof(Unit) });
args = new object[] { u.Unit };
}
Debug.Assert(member != null, "Looks like we're missing FontUnit static fields or FontUnit::ctor(Unit)");
if (member != null) {
return new InstanceDescriptor(member, args);
}
else {
return null;
}
}
else {
return base.ConvertTo(context, culture, value, destinationType);
}
}
///
/// Returns a
/// containing standard values.
///
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
if (values == null) {
object[] namedUnits = new object[] {
FontUnit.Smaller,
FontUnit.Larger,
FontUnit.XXSmall,
FontUnit.XSmall,
FontUnit.Small,
FontUnit.Medium,
FontUnit.Large,
FontUnit.XLarge,
FontUnit.XXLarge
};
values = new StandardValuesCollection(namedUnits);
}
return values;
}
///
/// Indicates whether the specified context contains exclusive standard
/// values.
///
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) {
return false;
}
///
/// Indicates whether the specified context contains suppurted standard
/// values.
///
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
return true;
}
}
}
// 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.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Reflection;
using System.Security.Permissions;
using System.Web.Util;
///
/// Converts a to and from a specified data type.
///
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class FontUnitConverter : TypeConverter {
private StandardValuesCollection values;
///
/// Determines if the specified data type can be converted to a .
///
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
if (sourceType == typeof(string)) {
return true;
}
else {
return base.CanConvertFrom(context, sourceType);
}
}
///
/// Converts the specified into a .
///
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
if (value == null)
return null;
string stringValue = value as string;
if (stringValue != null) {
string textValue = stringValue.Trim();
if (textValue.Length == 0) {
return FontUnit.Empty;
}
return FontUnit.Parse(textValue, culture);
}
else {
return base.ConvertFrom(context, culture, value);
}
}
///
///
/// Returns a value indicating whether the converter can
/// convert to the specified destination type.
///
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
if ((destinationType == typeof(string)) ||
(destinationType == typeof(InstanceDescriptor))) {
return true;
}
else {
return base.CanConvertTo(context, destinationType);
}
}
///
/// Converts the specified into the specified .
///
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
if (destinationType == typeof(string)) {
if ((value == null) || (((FontUnit)value).Type == FontSize.NotSet))
return String.Empty;
else
return ((FontUnit)value).ToString(culture);
}
else if ((destinationType == typeof(InstanceDescriptor)) && (value != null)) {
FontUnit u = (FontUnit)value;
MemberInfo member = null;
object[] args = null;
if (u.IsEmpty) {
member = typeof(FontUnit).GetField("Empty");
}
else if (u.Type != FontSize.AsUnit) {
string fieldName = null;
switch (u.Type) {
case FontSize.Smaller:
fieldName = "Smaller";
break;
case FontSize.Larger:
fieldName = "Larger";
break;
case FontSize.XXSmall:
fieldName = "XXSmall";
break;
case FontSize.XSmall:
fieldName = "XSmall";
break;
case FontSize.Small:
fieldName = "Small";
break;
case FontSize.Medium:
fieldName = "Medium";
break;
case FontSize.Large:
fieldName = "Large";
break;
case FontSize.XLarge:
fieldName = "XLarge";
break;
case FontSize.XXLarge:
fieldName = "XXLarge";
break;
}
Debug.Assert(fieldName != null, "Invalid FontSize type");
if (fieldName != null) {
member = typeof(FontUnit).GetField(fieldName);
}
}
else {
member = typeof(FontUnit).GetConstructor(new Type[] { typeof(Unit) });
args = new object[] { u.Unit };
}
Debug.Assert(member != null, "Looks like we're missing FontUnit static fields or FontUnit::ctor(Unit)");
if (member != null) {
return new InstanceDescriptor(member, args);
}
else {
return null;
}
}
else {
return base.ConvertTo(context, culture, value, destinationType);
}
}
///
/// Returns a
/// containing standard values.
///
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
if (values == null) {
object[] namedUnits = new object[] {
FontUnit.Smaller,
FontUnit.Larger,
FontUnit.XXSmall,
FontUnit.XSmall,
FontUnit.Small,
FontUnit.Medium,
FontUnit.Large,
FontUnit.XLarge,
FontUnit.XXLarge
};
values = new StandardValuesCollection(namedUnits);
}
return values;
}
///
/// Indicates whether the specified context contains exclusive standard
/// values.
///
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) {
return false;
}
///
/// Indicates whether the specified context contains suppurted standard
/// values.
///
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
return true;
}
}
}
// 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
- DBParameter.cs
- DiscoveryVersionConverter.cs
- SafeSystemMetrics.cs
- ObjectStateEntry.cs
- PixelFormats.cs
- BulletedListEventArgs.cs
- MtomMessageEncodingElement.cs
- DataSourceCache.cs
- TypedReference.cs
- ParseHttpDate.cs
- CorrelationHandle.cs
- OdbcInfoMessageEvent.cs
- WriteStateInfoBase.cs
- VectorCollection.cs
- ListBoxItem.cs
- templategroup.cs
- HierarchicalDataSourceControl.cs
- QueryStringParameter.cs
- SynchronousChannel.cs
- WebPartAuthorizationEventArgs.cs
- SqlCommandBuilder.cs
- ImageMetadata.cs
- BindingsCollection.cs
- DbReferenceCollection.cs
- DefaultEvaluationContext.cs
- BinaryCommonClasses.cs
- KeyTimeConverter.cs
- DiscoveryReferences.cs
- InvariantComparer.cs
- MasterPageParser.cs
- SoapFault.cs
- JavaScriptString.cs
- FreezableOperations.cs
- EntityDataSourceChangingEventArgs.cs
- XmlDataSourceNodeDescriptor.cs
- QueueAccessMode.cs
- StrokeDescriptor.cs
- WebPartsPersonalizationAuthorization.cs
- RegistrationServices.cs
- UserControl.cs
- ObjectStateEntryDbDataRecord.cs
- TablePattern.cs
- MenuRenderer.cs
- GeneralTransform3DCollection.cs
- SetterBase.cs
- MD5.cs
- QuaternionAnimationBase.cs
- InvalidDataException.cs
- RoutedUICommand.cs
- TextAdaptor.cs
- Char.cs
- EntityExpressionVisitor.cs
- OracleString.cs
- ArrayExtension.cs
- Sql8ExpressionRewriter.cs
- RegionIterator.cs
- TextEndOfParagraph.cs
- InvalidCommandTreeException.cs
- AttributeUsageAttribute.cs
- SqlConnectionHelper.cs
- CompilerGlobalScopeAttribute.cs
- InputDevice.cs
- InputBinder.cs
- AsyncSerializedWorker.cs
- PropertyGridCommands.cs
- RSACryptoServiceProvider.cs
- ProtectedConfigurationSection.cs
- CapabilitiesUse.cs
- Visual.cs
- DesignerCategoryAttribute.cs
- XPathArrayIterator.cs
- RefExpr.cs
- CreateInstanceBinder.cs
- CodeMemberField.cs
- TreeNodeSelectionProcessor.cs
- MiniModule.cs
- X509ClientCertificateCredentialsElement.cs
- PersonalizablePropertyEntry.cs
- ActiveXSite.cs
- KnownAssemblyEntry.cs
- DialogResultConverter.cs
- RelationshipSet.cs
- Rectangle.cs
- ParagraphVisual.cs
- ProtectedConfiguration.cs
- _HeaderInfo.cs
- InvalidProgramException.cs
- BrowsableAttribute.cs
- AppliesToBehaviorDecisionTable.cs
- JpegBitmapEncoder.cs
- InstrumentationTracker.cs
- MoveSizeWinEventHandler.cs
- ConfigsHelper.cs
- DataGridViewRowPrePaintEventArgs.cs
- DataGridViewLinkColumn.cs
- QilStrConcatenator.cs
- AmbiguousMatchException.cs
- ListSortDescription.cs
- ClrPerspective.cs
- Thickness.cs