Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Base / System / Windows / Threading / PriorityRange.cs / 1 / PriorityRange.cs
using System;
namespace System.Windows.Threading
{
///
/// Represents a range of priorities.
///
internal struct PriorityRange
{
///
/// The range of all possible priorities.
///
public static readonly PriorityRange All = new PriorityRange(DispatcherPriority.Inactive, DispatcherPriority.Send, true); // NOTE: should be Priority
///
/// A range that includes no priorities.
///
public static readonly PriorityRange None = new PriorityRange(DispatcherPriority.Invalid, DispatcherPriority.Invalid, true); // NOTE: should be Priority
///
/// Constructs an instance of the PriorityRange class.
///
public PriorityRange(DispatcherPriority min, DispatcherPriority max) : this() // NOTE: should be Priority
{
Initialize(min, true, max, true);
}
///
/// Constructs an instance of the PriorityRange class.
///
public PriorityRange(DispatcherPriority min, bool isMinInclusive, DispatcherPriority max, bool isMaxInclusive) : this() // NOTE: should be Priority
{
Initialize(min, isMinInclusive, max, isMaxInclusive);
}
///
/// The minimum priority of this range.
///
public DispatcherPriority Min // NOTE: should be Priority
{
get
{
return _min;
}
}
///
/// The maximum priority of this range.
///
public DispatcherPriority Max // NOTE: should be Priority
{
get
{
return _max;
}
}
///
/// Whether or not the minimum priority in included in this range.
///
public bool IsMinInclusive
{
get
{
return _isMinInclusive;
}
}
///
/// Whether or not the maximum priority in included in this range.
///
public bool IsMaxInclusive
{
get
{
return _isMaxInclusive;
}
}
///
/// Whether or not this priority range is valid.
///
public bool IsValid
{
get
{
// return _min != null && _min.IsValid && _max != null && _max.IsValid;
return (_min > DispatcherPriority.Invalid && _min <= DispatcherPriority.Send &&
_max > DispatcherPriority.Invalid && _max <= DispatcherPriority.Send);
}
}
///
/// Whether or not this priority range contains the specified
/// priority.
///
public bool Contains(DispatcherPriority priority) // NOTE: should be Priority
{
/*
if (priority == null || !priority.IsValid)
{
return false;
}
*/
if(priority <= DispatcherPriority.Invalid || priority > DispatcherPriority.Send)
{
return false;
}
if (!IsValid)
{
return false;
}
bool contains = false;
if (_isMinInclusive)
{
contains = (priority >= _min);
}
else
{
contains = (priority > _min);
}
if (contains)
{
if (_isMaxInclusive)
{
contains = (priority <= _max);
}
else
{
contains = (priority < _max);
}
}
return contains;
}
///
/// Whether or not this priority range contains the specified
/// priority range.
///
public bool Contains(PriorityRange priorityRange)
{
if (!priorityRange.IsValid)
{
return false;
}
if (!IsValid)
{
return false;
}
bool contains = false;
if (priorityRange._isMinInclusive)
{
contains = Contains(priorityRange.Min);
}
else
{
if(priorityRange.Min >= _min && priorityRange.Min < _max)
{
contains = true;
}
}
if (contains)
{
if (priorityRange._isMaxInclusive)
{
contains = Contains(priorityRange.Max);
}
else
{
if(priorityRange.Max > _min && priorityRange.Max <= _max)
{
contains = true;
}
}
}
return contains;
}
///
/// Equality method for two PriorityRange
///
public override bool Equals(object o)
{
if(o is PriorityRange)
{
return Equals((PriorityRange) o);
}
else
{
return false;
}
}
///
/// Equality method for two PriorityRange
///
public bool Equals(PriorityRange priorityRange)
{
return priorityRange._min == this._min &&
priorityRange._isMinInclusive == this._isMinInclusive &&
priorityRange._max == this._max &&
priorityRange._isMaxInclusive == this._isMaxInclusive;
}
///
/// Equality operator
///
public static bool operator== (PriorityRange priorityRange1, PriorityRange priorityRange2)
{
return priorityRange1.Equals(priorityRange2);
}
///
/// Inequality operator
///
public static bool operator!= (PriorityRange priorityRange1, PriorityRange priorityRange2)
{
return !(priorityRange1 == priorityRange2);
}
///
/// Returns a reasonable hash code for this PriorityRange instance.
///
public override int GetHashCode()
{
return base.GetHashCode();
}
private void Initialize(DispatcherPriority min, bool isMinInclusive, DispatcherPriority max, bool isMaxInclusive) // NOTE: should be Priority
{
/*
if(min == null)
{
throw new ArgumentNullException("min");
}
if (!min.IsValid)
{
throw new ArgumentException("Invalid priority.", "min");
}
*/
if(min < DispatcherPriority.Invalid || min > DispatcherPriority.Send)
{
// If we move to a Priority class, this exception will have to change too.
throw new System.ComponentModel.InvalidEnumArgumentException("min", (int)min, typeof(DispatcherPriority));
}
if(min == DispatcherPriority.Inactive)
{
throw new ArgumentException(SR.Get(SRID.InvalidPriority), "min");
}
/*
if(max == null)
{
throw new ArgumentNullException("max");
}
if (!max.IsValid)
{
throw new ArgumentException("Invalid priority.", "max");
}
*/
if(max < DispatcherPriority.Invalid || max > DispatcherPriority.Send)
{
// If we move to a Priority class, this exception will have to change too.
throw new System.ComponentModel.InvalidEnumArgumentException("max", (int)max, typeof(DispatcherPriority));
}
if(max == DispatcherPriority.Inactive)
{
throw new ArgumentException(SR.Get(SRID.InvalidPriority), "max");
}
if (max < min)
{
throw new ArgumentException(SR.Get(SRID.InvalidPriorityRangeOrder));
}
_min = min;
_isMinInclusive = isMinInclusive;
_max = max;
_isMaxInclusive = isMaxInclusive;
}
// This is a constructor for our special static members.
private PriorityRange(DispatcherPriority min, DispatcherPriority max, bool ignored) // NOTE: should be Priority
{
_min = min;
_isMinInclusive = true;
_max = max;
_isMaxInclusive = true;
}
private DispatcherPriority _min; // NOTE: should be Priority
private bool _isMinInclusive;
private DispatcherPriority _max; // NOTE: should be Priority
private bool _isMaxInclusive;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
namespace System.Windows.Threading
{
///
/// Represents a range of priorities.
///
internal struct PriorityRange
{
///
/// The range of all possible priorities.
///
public static readonly PriorityRange All = new PriorityRange(DispatcherPriority.Inactive, DispatcherPriority.Send, true); // NOTE: should be Priority
///
/// A range that includes no priorities.
///
public static readonly PriorityRange None = new PriorityRange(DispatcherPriority.Invalid, DispatcherPriority.Invalid, true); // NOTE: should be Priority
///
/// Constructs an instance of the PriorityRange class.
///
public PriorityRange(DispatcherPriority min, DispatcherPriority max) : this() // NOTE: should be Priority
{
Initialize(min, true, max, true);
}
///
/// Constructs an instance of the PriorityRange class.
///
public PriorityRange(DispatcherPriority min, bool isMinInclusive, DispatcherPriority max, bool isMaxInclusive) : this() // NOTE: should be Priority
{
Initialize(min, isMinInclusive, max, isMaxInclusive);
}
///
/// The minimum priority of this range.
///
public DispatcherPriority Min // NOTE: should be Priority
{
get
{
return _min;
}
}
///
/// The maximum priority of this range.
///
public DispatcherPriority Max // NOTE: should be Priority
{
get
{
return _max;
}
}
///
/// Whether or not the minimum priority in included in this range.
///
public bool IsMinInclusive
{
get
{
return _isMinInclusive;
}
}
///
/// Whether or not the maximum priority in included in this range.
///
public bool IsMaxInclusive
{
get
{
return _isMaxInclusive;
}
}
///
/// Whether or not this priority range is valid.
///
public bool IsValid
{
get
{
// return _min != null && _min.IsValid && _max != null && _max.IsValid;
return (_min > DispatcherPriority.Invalid && _min <= DispatcherPriority.Send &&
_max > DispatcherPriority.Invalid && _max <= DispatcherPriority.Send);
}
}
///
/// Whether or not this priority range contains the specified
/// priority.
///
public bool Contains(DispatcherPriority priority) // NOTE: should be Priority
{
/*
if (priority == null || !priority.IsValid)
{
return false;
}
*/
if(priority <= DispatcherPriority.Invalid || priority > DispatcherPriority.Send)
{
return false;
}
if (!IsValid)
{
return false;
}
bool contains = false;
if (_isMinInclusive)
{
contains = (priority >= _min);
}
else
{
contains = (priority > _min);
}
if (contains)
{
if (_isMaxInclusive)
{
contains = (priority <= _max);
}
else
{
contains = (priority < _max);
}
}
return contains;
}
///
/// Whether or not this priority range contains the specified
/// priority range.
///
public bool Contains(PriorityRange priorityRange)
{
if (!priorityRange.IsValid)
{
return false;
}
if (!IsValid)
{
return false;
}
bool contains = false;
if (priorityRange._isMinInclusive)
{
contains = Contains(priorityRange.Min);
}
else
{
if(priorityRange.Min >= _min && priorityRange.Min < _max)
{
contains = true;
}
}
if (contains)
{
if (priorityRange._isMaxInclusive)
{
contains = Contains(priorityRange.Max);
}
else
{
if(priorityRange.Max > _min && priorityRange.Max <= _max)
{
contains = true;
}
}
}
return contains;
}
///
/// Equality method for two PriorityRange
///
public override bool Equals(object o)
{
if(o is PriorityRange)
{
return Equals((PriorityRange) o);
}
else
{
return false;
}
}
///
/// Equality method for two PriorityRange
///
public bool Equals(PriorityRange priorityRange)
{
return priorityRange._min == this._min &&
priorityRange._isMinInclusive == this._isMinInclusive &&
priorityRange._max == this._max &&
priorityRange._isMaxInclusive == this._isMaxInclusive;
}
///
/// Equality operator
///
public static bool operator== (PriorityRange priorityRange1, PriorityRange priorityRange2)
{
return priorityRange1.Equals(priorityRange2);
}
///
/// Inequality operator
///
public static bool operator!= (PriorityRange priorityRange1, PriorityRange priorityRange2)
{
return !(priorityRange1 == priorityRange2);
}
///
/// Returns a reasonable hash code for this PriorityRange instance.
///
public override int GetHashCode()
{
return base.GetHashCode();
}
private void Initialize(DispatcherPriority min, bool isMinInclusive, DispatcherPriority max, bool isMaxInclusive) // NOTE: should be Priority
{
/*
if(min == null)
{
throw new ArgumentNullException("min");
}
if (!min.IsValid)
{
throw new ArgumentException("Invalid priority.", "min");
}
*/
if(min < DispatcherPriority.Invalid || min > DispatcherPriority.Send)
{
// If we move to a Priority class, this exception will have to change too.
throw new System.ComponentModel.InvalidEnumArgumentException("min", (int)min, typeof(DispatcherPriority));
}
if(min == DispatcherPriority.Inactive)
{
throw new ArgumentException(SR.Get(SRID.InvalidPriority), "min");
}
/*
if(max == null)
{
throw new ArgumentNullException("max");
}
if (!max.IsValid)
{
throw new ArgumentException("Invalid priority.", "max");
}
*/
if(max < DispatcherPriority.Invalid || max > DispatcherPriority.Send)
{
// If we move to a Priority class, this exception will have to change too.
throw new System.ComponentModel.InvalidEnumArgumentException("max", (int)max, typeof(DispatcherPriority));
}
if(max == DispatcherPriority.Inactive)
{
throw new ArgumentException(SR.Get(SRID.InvalidPriority), "max");
}
if (max < min)
{
throw new ArgumentException(SR.Get(SRID.InvalidPriorityRangeOrder));
}
_min = min;
_isMinInclusive = isMinInclusive;
_max = max;
_isMaxInclusive = isMaxInclusive;
}
// This is a constructor for our special static members.
private PriorityRange(DispatcherPriority min, DispatcherPriority max, bool ignored) // NOTE: should be Priority
{
_min = min;
_isMinInclusive = true;
_max = max;
_isMaxInclusive = true;
}
private DispatcherPriority _min; // NOTE: should be Priority
private bool _isMinInclusive;
private DispatcherPriority _max; // NOTE: should be Priority
private bool _isMaxInclusive;
}
}
// 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
- GradientSpreadMethodValidation.cs
- SymbolPair.cs
- Line.cs
- Span.cs
- TransformerInfoCollection.cs
- SurrogateEncoder.cs
- TreeNodeBindingCollection.cs
- ContextConfiguration.cs
- CoreSwitches.cs
- XmlByteStreamReader.cs
- StreamResourceInfo.cs
- HtmlButton.cs
- DataStreamFromComStream.cs
- DefaultValueTypeConverter.cs
- Method.cs
- InternalCache.cs
- MouseDevice.cs
- _ListenerResponseStream.cs
- MachineKey.cs
- Stylus.cs
- TargetParameterCountException.cs
- EntityDataSourceView.cs
- RepeatInfo.cs
- DataGridViewCellStyle.cs
- FilePresentation.cs
- WebRequestModuleElementCollection.cs
- StdValidatorsAndConverters.cs
- RegionIterator.cs
- ApplicationManager.cs
- EndpointNotFoundException.cs
- ToolStripGripRenderEventArgs.cs
- XamlPointCollectionSerializer.cs
- CodeExpressionCollection.cs
- EdmSchemaAttribute.cs
- ControlTemplate.cs
- SystemKeyConverter.cs
- VarRemapper.cs
- SafeLocalMemHandle.cs
- PublisherIdentityPermission.cs
- LinqDataSourceSelectEventArgs.cs
- XamlVector3DCollectionSerializer.cs
- BuilderPropertyEntry.cs
- DataControlExtensions.cs
- ColumnTypeConverter.cs
- XmlAttributeCollection.cs
- InvalidProgramException.cs
- RichTextBoxConstants.cs
- HttpCookie.cs
- HttpCacheVary.cs
- MimeObjectFactory.cs
- StrongNameMembershipCondition.cs
- VerticalAlignConverter.cs
- ActivationArguments.cs
- SmiMetaDataProperty.cs
- PolyBezierSegment.cs
- EventManager.cs
- VariantWrapper.cs
- x509utils.cs
- ControlEvent.cs
- ZipPackage.cs
- DataColumnChangeEvent.cs
- GlobalDataBindingHandler.cs
- DocumentSequence.cs
- ParamArrayAttribute.cs
- Imaging.cs
- BmpBitmapDecoder.cs
- XmlSchemaValidationException.cs
- SafeViewOfFileHandle.cs
- ModelEditingScope.cs
- FusionWrap.cs
- XmlText.cs
- RawStylusSystemGestureInputReport.cs
- MessageRpc.cs
- WindowsImpersonationContext.cs
- DebuggerService.cs
- SafeLocalMemHandle.cs
- TableRowGroupCollection.cs
- DateTimeFormatInfoScanner.cs
- UserControlParser.cs
- Attributes.cs
- XmlIterators.cs
- KeyTime.cs
- BitmapEffectCollection.cs
- ObjectListFieldsPage.cs
- BoundsDrawingContextWalker.cs
- DebuggerAttributes.cs
- CngAlgorithm.cs
- _NegotiateClient.cs
- DeferredReference.cs
- PassportAuthenticationModule.cs
- XmlCharCheckingReader.cs
- SoapAttributes.cs
- SortableBindingList.cs
- DataGridViewColumnCollectionDialog.cs
- ThreadExceptionDialog.cs
- SqlUtil.cs
- PcmConverter.cs
- HttpContextWrapper.cs
- ElementMarkupObject.cs
- RoleManagerModule.cs