Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Core / CSharp / System / Windows / Media / Animation / KeyTime.cs / 1 / KeyTime.cs
// KeyTime.cs
// Allow suppression of certain presharp messages
#pragma warning disable 1634, 1691
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
namespace System.Windows.Media.Animation
{
///
/// A KeyTime is use to specify when relative to the time of an animation
/// that a KeyFrame takes place.
///
[TypeConverter(typeof(KeyTimeConverter))]
public struct KeyTime : IEquatable
{
private object _value;
private KeyTimeType _type;
#region Static Create Methods
///
/// Creates a KeyTime that represents a Percent value.
///
///
/// The percent value provided as a double value between 0.0 and 1.0.
///
public static KeyTime FromPercent(double percent)
{
if (percent < 0.0 || percent > 1.0)
{
throw new ArgumentOutOfRangeException("percent", SR.Get(SRID.Animation_KeyTime_InvalidPercentValue, percent));
}
KeyTime keyTime = new KeyTime();
keyTime._value = percent;
keyTime._type = KeyTimeType.Percent;
return keyTime;
}
///
///
///
///
public static KeyTime FromTimeSpan(TimeSpan timeSpan)
{
if (timeSpan < TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException("timeSpan", SR.Get(SRID.Animation_KeyTime_LessThanZero, timeSpan));
}
KeyTime keyTime = new KeyTime();
keyTime._value = timeSpan;
keyTime._type = KeyTimeType.TimeSpan;
return keyTime;
}
///
///
///
///
public static KeyTime Uniform
{
get
{
KeyTime keyTime = new KeyTime();
keyTime._type = KeyTimeType.Uniform;
return keyTime;
}
}
///
///
///
///
public static KeyTime Paced
{
get
{
KeyTime keyTime = new KeyTime();
keyTime._type = KeyTimeType.Paced;
return keyTime;
}
}
#endregion
#region Operators
///
/// Returns true if two KeyTimes are equal.
///
public static bool Equals(KeyTime keyTime1, KeyTime keyTime2)
{
if (keyTime1._type == keyTime2._type)
{
switch (keyTime1._type)
{
case KeyTimeType.Uniform:
break;
case KeyTimeType.Paced:
break;
case KeyTimeType.Percent:
if ((double)keyTime1._value != (double)keyTime2._value)
{
return false;
}
break;
case KeyTimeType.TimeSpan:
if ((TimeSpan)keyTime1._value != (TimeSpan)keyTime2._value)
{
return false;
}
break;
}
return true;
}
else
{
return false;
}
}
///
/// Returns true if two KeyTimes are equal.
///
public static bool operator ==(KeyTime keyTime1, KeyTime keyTime2)
{
return KeyTime.Equals(keyTime1, keyTime2);
}
///
/// Returns true if two KeyTimes are not equal.
///
public static bool operator !=(KeyTime keyTime1, KeyTime keyTime2)
{
return !KeyTime.Equals(keyTime1, keyTime2);
}
#endregion
#region IEquatable
///
/// Returns true if two KeyTimes are equal.
///
public bool Equals(KeyTime value)
{
return KeyTime.Equals(this, value);
}
#endregion
#region Object Overrides
///
/// Implementation of Object.Equals .
///
public override bool Equals(object value)
{
if ( value == null
|| !(value is KeyTime))
{
return false;
}
return this == (KeyTime)value;
}
///
/// Implementation of Object.GetHashCode .
///
public override int GetHashCode()
{
// If we don't have a value (uniform, or paced) then use the type
// to determine the hash code
if (_value != null)
{
return _value.GetHashCode();
}
else
{
return _type.GetHashCode();
}
}
///
/// Generates a string representing this KeyTime.
///
/// The generated string.
public override string ToString()
{
KeyTimeConverter converter = new KeyTimeConverter();
return converter.ConvertToString(this);
}
#endregion
#region Implicit Converters
///
/// Implicitly creates a KeyTime value from a Time value.
///
/// The Time value.
/// A new KeyTime.
public static implicit operator KeyTime(TimeSpan timeSpan)
{
return KeyTime.FromTimeSpan(timeSpan);
}
#endregion
#region Public Properties
///
/// The Time value for this KeyTime.
///
///
/// Thrown if the type of this KeyTime isn't KeyTimeType.TimeSpan.
///
public TimeSpan TimeSpan
{
get
{
if (_type == KeyTimeType.TimeSpan)
{
return (TimeSpan)_value;
}
else
{
#pragma warning suppress 56503 // Suppress presharp warning: Follows a pattern similar to Nullable.
throw new InvalidOperationException();
}
}
}
///
/// The percent value for this KeyTime.
///
///
/// Thrown if the type of this KeyTime isn't KeyTimeType.Percent.
///
public double Percent
{
get
{
if (_type == KeyTimeType.Percent)
{
return (double)_value;
}
else
{
#pragma warning suppress 56503 // Suppress presharp warning: Follows a pattern similar to Nullable.
throw new InvalidOperationException();
}
}
}
///
/// The type of this KeyTime.
///
public KeyTimeType Type
{
get
{
return _type;
}
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
// KeyTime.cs
// Allow suppression of certain presharp messages
#pragma warning disable 1634, 1691
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
namespace System.Windows.Media.Animation
{
///
/// A KeyTime is use to specify when relative to the time of an animation
/// that a KeyFrame takes place.
///
[TypeConverter(typeof(KeyTimeConverter))]
public struct KeyTime : IEquatable
{
private object _value;
private KeyTimeType _type;
#region Static Create Methods
///
/// Creates a KeyTime that represents a Percent value.
///
///
/// The percent value provided as a double value between 0.0 and 1.0.
///
public static KeyTime FromPercent(double percent)
{
if (percent < 0.0 || percent > 1.0)
{
throw new ArgumentOutOfRangeException("percent", SR.Get(SRID.Animation_KeyTime_InvalidPercentValue, percent));
}
KeyTime keyTime = new KeyTime();
keyTime._value = percent;
keyTime._type = KeyTimeType.Percent;
return keyTime;
}
///
///
///
///
public static KeyTime FromTimeSpan(TimeSpan timeSpan)
{
if (timeSpan < TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException("timeSpan", SR.Get(SRID.Animation_KeyTime_LessThanZero, timeSpan));
}
KeyTime keyTime = new KeyTime();
keyTime._value = timeSpan;
keyTime._type = KeyTimeType.TimeSpan;
return keyTime;
}
///
///
///
///
public static KeyTime Uniform
{
get
{
KeyTime keyTime = new KeyTime();
keyTime._type = KeyTimeType.Uniform;
return keyTime;
}
}
///
///
///
///
public static KeyTime Paced
{
get
{
KeyTime keyTime = new KeyTime();
keyTime._type = KeyTimeType.Paced;
return keyTime;
}
}
#endregion
#region Operators
///
/// Returns true if two KeyTimes are equal.
///
public static bool Equals(KeyTime keyTime1, KeyTime keyTime2)
{
if (keyTime1._type == keyTime2._type)
{
switch (keyTime1._type)
{
case KeyTimeType.Uniform:
break;
case KeyTimeType.Paced:
break;
case KeyTimeType.Percent:
if ((double)keyTime1._value != (double)keyTime2._value)
{
return false;
}
break;
case KeyTimeType.TimeSpan:
if ((TimeSpan)keyTime1._value != (TimeSpan)keyTime2._value)
{
return false;
}
break;
}
return true;
}
else
{
return false;
}
}
///
/// Returns true if two KeyTimes are equal.
///
public static bool operator ==(KeyTime keyTime1, KeyTime keyTime2)
{
return KeyTime.Equals(keyTime1, keyTime2);
}
///
/// Returns true if two KeyTimes are not equal.
///
public static bool operator !=(KeyTime keyTime1, KeyTime keyTime2)
{
return !KeyTime.Equals(keyTime1, keyTime2);
}
#endregion
#region IEquatable
///
/// Returns true if two KeyTimes are equal.
///
public bool Equals(KeyTime value)
{
return KeyTime.Equals(this, value);
}
#endregion
#region Object Overrides
///
/// Implementation of Object.Equals .
///
public override bool Equals(object value)
{
if ( value == null
|| !(value is KeyTime))
{
return false;
}
return this == (KeyTime)value;
}
///
/// Implementation of Object.GetHashCode .
///
public override int GetHashCode()
{
// If we don't have a value (uniform, or paced) then use the type
// to determine the hash code
if (_value != null)
{
return _value.GetHashCode();
}
else
{
return _type.GetHashCode();
}
}
///
/// Generates a string representing this KeyTime.
///
/// The generated string.
public override string ToString()
{
KeyTimeConverter converter = new KeyTimeConverter();
return converter.ConvertToString(this);
}
#endregion
#region Implicit Converters
///
/// Implicitly creates a KeyTime value from a Time value.
///
/// The Time value.
/// A new KeyTime.
public static implicit operator KeyTime(TimeSpan timeSpan)
{
return KeyTime.FromTimeSpan(timeSpan);
}
#endregion
#region Public Properties
///
/// The Time value for this KeyTime.
///
///
/// Thrown if the type of this KeyTime isn't KeyTimeType.TimeSpan.
///
public TimeSpan TimeSpan
{
get
{
if (_type == KeyTimeType.TimeSpan)
{
return (TimeSpan)_value;
}
else
{
#pragma warning suppress 56503 // Suppress presharp warning: Follows a pattern similar to Nullable.
throw new InvalidOperationException();
}
}
}
///
/// The percent value for this KeyTime.
///
///
/// Thrown if the type of this KeyTime isn't KeyTimeType.Percent.
///
public double Percent
{
get
{
if (_type == KeyTimeType.Percent)
{
return (double)_value;
}
else
{
#pragma warning suppress 56503 // Suppress presharp warning: Follows a pattern similar to Nullable.
throw new InvalidOperationException();
}
}
}
///
/// The type of this KeyTime.
///
public KeyTimeType Type
{
get
{
return _type;
}
}
#endregion
}
}
// 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
- InvalidOperationException.cs
- ClusterSafeNativeMethods.cs
- GeneralTransform3DTo2DTo3D.cs
- FormsAuthenticationCredentials.cs
- RecommendedAsConfigurableAttribute.cs
- ReadOnlyDictionary.cs
- MarkupCompiler.cs
- ConversionContext.cs
- HandoffBehavior.cs
- ServiceOperation.cs
- DockProviderWrapper.cs
- DataGridColumnCollection.cs
- TrackingProfile.cs
- DiscoveryRequestHandler.cs
- CreateUserWizard.cs
- FolderLevelBuildProviderAppliesToAttribute.cs
- RootBrowserWindow.cs
- ChameleonKey.cs
- DataGridViewColumnStateChangedEventArgs.cs
- BrushValueSerializer.cs
- VisualStyleTypesAndProperties.cs
- WeakReference.cs
- RSAPKCS1SignatureDeformatter.cs
- OdbcEnvironmentHandle.cs
- ActivityDesignerHighlighter.cs
- SymbolDocumentGenerator.cs
- ProtocolsSection.cs
- _SslSessionsCache.cs
- PathFigureCollection.cs
- EntityTypeEmitter.cs
- System.Data.OracleClient_BID.cs
- StringAnimationUsingKeyFrames.cs
- DetailsViewInsertEventArgs.cs
- TypeHelper.cs
- GeneralTransformCollection.cs
- Hex.cs
- Pair.cs
- PrintPreviewGraphics.cs
- MsmqBindingFilter.cs
- NonParentingControl.cs
- Activator.cs
- OletxEnlistment.cs
- DocumentStatusResources.cs
- OutputCacheSettingsSection.cs
- MenuItemStyle.cs
- GlyphInfoList.cs
- OledbConnectionStringbuilder.cs
- DataGridViewColumnCollectionDialog.cs
- CodeGen.cs
- ServiceOperationListItemList.cs
- ListViewItemEventArgs.cs
- UInt16.cs
- DesignerGenericWebPart.cs
- ActivationService.cs
- CharacterBufferReference.cs
- SoapIncludeAttribute.cs
- DataGridViewCellToolTipTextNeededEventArgs.cs
- GPRECT.cs
- DesignDataSource.cs
- TailCallAnalyzer.cs
- DataRelation.cs
- ProgressBarHighlightConverter.cs
- RootProfilePropertySettingsCollection.cs
- TextRangeBase.cs
- MulticastNotSupportedException.cs
- TypeBuilderInstantiation.cs
- DataRowChangeEvent.cs
- DataGridViewToolTip.cs
- DataGridViewLinkColumn.cs
- TrackingSection.cs
- CLSCompliantAttribute.cs
- DataGridState.cs
- _AutoWebProxyScriptWrapper.cs
- ListManagerBindingsCollection.cs
- DefaultProxySection.cs
- UnsafeNativeMethods.cs
- PostBackOptions.cs
- AppSettingsSection.cs
- xdrvalidator.cs
- CodeSubDirectory.cs
- embossbitmapeffect.cs
- ResolveInfo.cs
- SystemWebCachingSectionGroup.cs
- EntityContainerEntitySet.cs
- EntityTypeEmitter.cs
- UseManagedPresentationBindingElement.cs
- ValidatorCompatibilityHelper.cs
- ToolStripItemGlyph.cs
- ZeroOpNode.cs
- CapabilitiesAssignment.cs
- Message.cs
- CodeNamespaceCollection.cs
- HttpConfigurationContext.cs
- Overlapped.cs
- InfoCardSymmetricCrypto.cs
- ValidationHelper.cs
- ObjectDisposedException.cs
- QueryContinueDragEvent.cs
- ErrorProvider.cs
- PlanCompilerUtil.cs