Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / ndp / fx / src / xsp / System / Web / UI / WebControls / FontUnit.cs / 2 / FontUnit.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System;
using System.ComponentModel;
using System.Globalization;
using System.Security.Permissions;
using System.Web.Util;
///
/// Respresent the font unit.
///
[
TypeConverterAttribute(typeof(FontUnitConverter))
]
[Serializable]
public struct FontUnit {
///
/// Specifies an empty . This field is read only.
///
public static readonly FontUnit Empty = new FontUnit();
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit Smaller = new FontUnit(FontSize.Smaller);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit Larger = new FontUnit(FontSize.Larger);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit XXSmall = new FontUnit(FontSize.XXSmall);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit XSmall = new FontUnit(FontSize.XSmall);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit Small = new FontUnit(FontSize.Small);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit Medium = new FontUnit(FontSize.Medium);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit Large = new FontUnit(FontSize.Large);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit XLarge = new FontUnit(FontSize.XLarge);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit XXLarge = new FontUnit(FontSize.XXLarge);
private readonly FontSize type;
private readonly Unit value;
///
/// Initializes a new instance of the class with a .
///
public FontUnit(FontSize type) {
if (type < FontSize.NotSet || type > FontSize.XXLarge) {
throw new ArgumentOutOfRangeException("type");
}
this.type = type;
if (this.type == FontSize.AsUnit) {
value = Unit.Point(10);
}
else {
value = Unit.Empty;
}
}
///
/// Initializes a new instance of the class with a .
///
public FontUnit(Unit value) {
this.type = FontSize.NotSet;
if (value.IsEmpty == false) {
this.type = FontSize.AsUnit;
this.value = value;
}
else {
this.value = Unit.Empty;
}
}
///
/// Initializes a new instance of the class with an integer value.
///
public FontUnit(int value) {
this.type = FontSize.AsUnit;
this.value = Unit.Point(value);
}
///
/// Initializes a new instance of the class with a double value.
///
public FontUnit(double value) : this(new Unit(value, UnitType.Point)) {
}
///
/// Initializes a new instance of the class with a double value.
///
public FontUnit(double value, UnitType type) : this(new Unit(value, type)) {
}
///
/// Initializes a new instance of the class with a string.
///
public FontUnit(string value) : this(value, CultureInfo.CurrentCulture) {
}
///
/// [To be supplied.]
///
public FontUnit(string value, CultureInfo culture) {
this.type = FontSize.NotSet;
this.value = Unit.Empty;
if (!String.IsNullOrEmpty(value)) {
// This is invariant because it acts like an enum with a number together.
// The enum part is invariant, but the number uses current culture.
char firstChar = Char.ToLower(value[0], CultureInfo.InvariantCulture);
if (firstChar == 'x') {
if (String.Equals(value, "xx-small", StringComparison.OrdinalIgnoreCase) ||
String.Equals(value, "xxsmall", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.XXSmall;
return;
}
else if (String.Equals(value, "x-small", StringComparison.OrdinalIgnoreCase) ||
String.Equals(value, "xsmall", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.XSmall;
return;
}
else if (String.Equals(value, "x-large", StringComparison.OrdinalIgnoreCase) ||
String.Equals(value, "xlarge", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.XLarge;
return;
}
else if (String.Equals(value, "xx-large", StringComparison.OrdinalIgnoreCase) ||
String.Equals(value, "xxlarge", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.XXLarge;
return;
}
}
else if (firstChar == 's') {
if (String.Equals(value, "small", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.Small;
return;
}
else if (String.Equals(value, "smaller", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.Smaller;
return;
}
}
else if (firstChar == 'l') {
if (String.Equals(value, "large", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.Large;
return;
}
if (String.Equals(value, "larger", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.Larger;
return;
}
}
else if ((firstChar == 'm') && String.Equals(value, "medium", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.Medium;
return;
}
this.value = new Unit(value, culture, UnitType.Point);
this.type = FontSize.AsUnit;
}
}
///
/// Indicates whether the font size has been set.
///
public bool IsEmpty {
get {
return type == FontSize.NotSet;
}
}
///
/// Indicates the font size by type.
///
public FontSize Type {
get {
return type;
}
}
///
/// Indicates the font size by .
///
public Unit Unit {
get {
return value;
}
}
///
/// [To be supplied.]
///
public override int GetHashCode() {
return HashCodeCombiner.CombineHashCodes(type.GetHashCode(), value.GetHashCode());
}
///
/// Determines if the specified is equivilent to the represented by this instance.
///
public override bool Equals(object obj) {
if (obj == null || !(obj is FontUnit))
return false;
FontUnit f = (FontUnit)obj;
if ((f.type == type) && (f.value == value)) {
return true;
}
return false;
}
///
/// Compares two objects for equality.
///
public static bool operator ==(FontUnit left, FontUnit right) {
return ((left.type == right.type) && (left.value == right.value));
}
///
/// Compares two objects
/// for inequality.
///
public static bool operator !=(FontUnit left, FontUnit right) {
return ((left.type != right.type) || (left.value != right.value));
}
///
/// [To be supplied.]
///
public static FontUnit Parse(string s) {
return new FontUnit(s, CultureInfo.InvariantCulture);
}
///
/// [To be supplied.]
///
public static FontUnit Parse(string s, CultureInfo culture) {
return new FontUnit(s, culture);
}
///
/// Creates a of type Point from an integer value.
///
public static FontUnit Point(int n) {
return new FontUnit(n);
}
///
/// Convert a to a string.
///
public override string ToString() {
return ToString((IFormatProvider)CultureInfo.CurrentCulture);
}
public string ToString(CultureInfo culture) {
return ToString((IFormatProvider)culture);
}
public string ToString(IFormatProvider formatProvider) {
string s = String.Empty;
if (IsEmpty)
return s;
switch (type) {
case FontSize.AsUnit:
s = value.ToString(formatProvider);
break;
case FontSize.XXSmall:
s = "XX-Small";
break;
case FontSize.XSmall:
s = "X-Small";
break;
case FontSize.XLarge:
s = "X-Large";
break;
case FontSize.XXLarge:
s = "XX-Large";
break;
default:
s = PropertyConverter.EnumToString(typeof(FontSize), type);
break;
}
return s;
}
///
/// Implicitly creates a of type Point from an integer value.
///
public static implicit operator FontUnit(int n) {
return FontUnit.Point(n);
}
}
}
// 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.ComponentModel;
using System.Globalization;
using System.Security.Permissions;
using System.Web.Util;
///
/// Respresent the font unit.
///
[
TypeConverterAttribute(typeof(FontUnitConverter))
]
[Serializable]
public struct FontUnit {
///
/// Specifies an empty . This field is read only.
///
public static readonly FontUnit Empty = new FontUnit();
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit Smaller = new FontUnit(FontSize.Smaller);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit Larger = new FontUnit(FontSize.Larger);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit XXSmall = new FontUnit(FontSize.XXSmall);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit XSmall = new FontUnit(FontSize.XSmall);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit Small = new FontUnit(FontSize.Small);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit Medium = new FontUnit(FontSize.Medium);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit Large = new FontUnit(FontSize.Large);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit XLarge = new FontUnit(FontSize.XLarge);
///
/// Specifies a with
/// font. This field is read only.
///
public static readonly FontUnit XXLarge = new FontUnit(FontSize.XXLarge);
private readonly FontSize type;
private readonly Unit value;
///
/// Initializes a new instance of the class with a .
///
public FontUnit(FontSize type) {
if (type < FontSize.NotSet || type > FontSize.XXLarge) {
throw new ArgumentOutOfRangeException("type");
}
this.type = type;
if (this.type == FontSize.AsUnit) {
value = Unit.Point(10);
}
else {
value = Unit.Empty;
}
}
///
/// Initializes a new instance of the class with a .
///
public FontUnit(Unit value) {
this.type = FontSize.NotSet;
if (value.IsEmpty == false) {
this.type = FontSize.AsUnit;
this.value = value;
}
else {
this.value = Unit.Empty;
}
}
///
/// Initializes a new instance of the class with an integer value.
///
public FontUnit(int value) {
this.type = FontSize.AsUnit;
this.value = Unit.Point(value);
}
///
/// Initializes a new instance of the class with a double value.
///
public FontUnit(double value) : this(new Unit(value, UnitType.Point)) {
}
///
/// Initializes a new instance of the class with a double value.
///
public FontUnit(double value, UnitType type) : this(new Unit(value, type)) {
}
///
/// Initializes a new instance of the class with a string.
///
public FontUnit(string value) : this(value, CultureInfo.CurrentCulture) {
}
///
/// [To be supplied.]
///
public FontUnit(string value, CultureInfo culture) {
this.type = FontSize.NotSet;
this.value = Unit.Empty;
if (!String.IsNullOrEmpty(value)) {
// This is invariant because it acts like an enum with a number together.
// The enum part is invariant, but the number uses current culture.
char firstChar = Char.ToLower(value[0], CultureInfo.InvariantCulture);
if (firstChar == 'x') {
if (String.Equals(value, "xx-small", StringComparison.OrdinalIgnoreCase) ||
String.Equals(value, "xxsmall", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.XXSmall;
return;
}
else if (String.Equals(value, "x-small", StringComparison.OrdinalIgnoreCase) ||
String.Equals(value, "xsmall", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.XSmall;
return;
}
else if (String.Equals(value, "x-large", StringComparison.OrdinalIgnoreCase) ||
String.Equals(value, "xlarge", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.XLarge;
return;
}
else if (String.Equals(value, "xx-large", StringComparison.OrdinalIgnoreCase) ||
String.Equals(value, "xxlarge", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.XXLarge;
return;
}
}
else if (firstChar == 's') {
if (String.Equals(value, "small", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.Small;
return;
}
else if (String.Equals(value, "smaller", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.Smaller;
return;
}
}
else if (firstChar == 'l') {
if (String.Equals(value, "large", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.Large;
return;
}
if (String.Equals(value, "larger", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.Larger;
return;
}
}
else if ((firstChar == 'm') && String.Equals(value, "medium", StringComparison.OrdinalIgnoreCase)) {
this.type = FontSize.Medium;
return;
}
this.value = new Unit(value, culture, UnitType.Point);
this.type = FontSize.AsUnit;
}
}
///
/// Indicates whether the font size has been set.
///
public bool IsEmpty {
get {
return type == FontSize.NotSet;
}
}
///
/// Indicates the font size by type.
///
public FontSize Type {
get {
return type;
}
}
///
/// Indicates the font size by .
///
public Unit Unit {
get {
return value;
}
}
///
/// [To be supplied.]
///
public override int GetHashCode() {
return HashCodeCombiner.CombineHashCodes(type.GetHashCode(), value.GetHashCode());
}
///
/// Determines if the specified is equivilent to the represented by this instance.
///
public override bool Equals(object obj) {
if (obj == null || !(obj is FontUnit))
return false;
FontUnit f = (FontUnit)obj;
if ((f.type == type) && (f.value == value)) {
return true;
}
return false;
}
///
/// Compares two objects for equality.
///
public static bool operator ==(FontUnit left, FontUnit right) {
return ((left.type == right.type) && (left.value == right.value));
}
///
/// Compares two objects
/// for inequality.
///
public static bool operator !=(FontUnit left, FontUnit right) {
return ((left.type != right.type) || (left.value != right.value));
}
///
/// [To be supplied.]
///
public static FontUnit Parse(string s) {
return new FontUnit(s, CultureInfo.InvariantCulture);
}
///
/// [To be supplied.]
///
public static FontUnit Parse(string s, CultureInfo culture) {
return new FontUnit(s, culture);
}
///
/// Creates a of type Point from an integer value.
///
public static FontUnit Point(int n) {
return new FontUnit(n);
}
///
/// Convert a to a string.
///
public override string ToString() {
return ToString((IFormatProvider)CultureInfo.CurrentCulture);
}
public string ToString(CultureInfo culture) {
return ToString((IFormatProvider)culture);
}
public string ToString(IFormatProvider formatProvider) {
string s = String.Empty;
if (IsEmpty)
return s;
switch (type) {
case FontSize.AsUnit:
s = value.ToString(formatProvider);
break;
case FontSize.XXSmall:
s = "XX-Small";
break;
case FontSize.XSmall:
s = "X-Small";
break;
case FontSize.XLarge:
s = "X-Large";
break;
case FontSize.XXLarge:
s = "XX-Large";
break;
default:
s = PropertyConverter.EnumToString(typeof(FontSize), type);
break;
}
return s;
}
///
/// Implicitly creates a of type Point from an integer value.
///
public static implicit operator FontUnit(int n) {
return FontUnit.Point(n);
}
}
}
// 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
- UriTemplateDispatchFormatter.cs
- XmlIlGenerator.cs
- httpapplicationstate.cs
- PageSetupDialog.cs
- SqlCaseSimplifier.cs
- JapaneseCalendar.cs
- SafeReversePInvokeHandle.cs
- CommandID.cs
- InstanceView.cs
- NativeMethods.cs
- NamespaceEmitter.cs
- InterleavedZipPartStream.cs
- _FtpDataStream.cs
- BaseProcessor.cs
- DictionaryTraceRecord.cs
- StyleConverter.cs
- Rect3D.cs
- LinearGradientBrush.cs
- FormsIdentity.cs
- DataControlButton.cs
- MultiPartWriter.cs
- TemplateBindingExtensionConverter.cs
- XamlReaderHelper.cs
- ClientConfigurationHost.cs
- SystemDiagnosticsSection.cs
- StreamSecurityUpgradeAcceptorBase.cs
- DesignSurfaceManager.cs
- ServicePoint.cs
- MergeFilterQuery.cs
- CmsInterop.cs
- FormsAuthenticationModule.cs
- EntityAdapter.cs
- AutoResetEvent.cs
- Lasso.cs
- HttpBufferlessInputStream.cs
- DataTableReaderListener.cs
- TypeContext.cs
- Transaction.cs
- ReachFixedDocumentSerializerAsync.cs
- HttpModulesSection.cs
- PeerName.cs
- MessageQueueEnumerator.cs
- ReplyAdapterChannelListener.cs
- ErrorWebPart.cs
- WindowAutomationPeer.cs
- StylusLogic.cs
- Peer.cs
- Converter.cs
- Win32PrintDialog.cs
- AnnotationMap.cs
- SecurityMode.cs
- RtfFormatStack.cs
- XmlSchemaAll.cs
- DataGridViewColumnCollection.cs
- AuthenticationModuleElementCollection.cs
- DbDataSourceEnumerator.cs
- SystemDropShadowChrome.cs
- DictionaryContent.cs
- SHA512.cs
- PatternMatchRules.cs
- GroupBox.cs
- DetailsViewUpdatedEventArgs.cs
- DataPagerField.cs
- SqlSupersetValidator.cs
- BlobPersonalizationState.cs
- PolicyUnit.cs
- ZipIOExtraFieldElement.cs
- AutoGeneratedFieldProperties.cs
- ValidatedControlConverter.cs
- ExpressionBuilder.cs
- ContainerAction.cs
- FormsAuthenticationUser.cs
- FrameworkTemplate.cs
- StdValidatorsAndConverters.cs
- XmlSchemaSimpleContentRestriction.cs
- MatrixAnimationBase.cs
- FileDialog.cs
- AutoCompleteStringCollection.cs
- DataGridHelper.cs
- PageContentCollection.cs
- KeyInterop.cs
- SendSecurityHeader.cs
- HtmlElementErrorEventArgs.cs
- CachedFontFamily.cs
- DataGridViewRowPostPaintEventArgs.cs
- ScrollProperties.cs
- __ComObject.cs
- FamilyCollection.cs
- ModuleBuilder.cs
- CacheOutputQuery.cs
- FragmentQuery.cs
- SqlParameter.cs
- DataServiceHostFactory.cs
- OleDbRowUpdatingEvent.cs
- Single.cs
- FrameDimension.cs
- FacetChecker.cs
- CharEntityEncoderFallback.cs
- CuspData.cs
- TextTabProperties.cs