本文整理汇总了C#中DateTimeOffset.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeOffset.Equals方法的具体用法?C# DateTimeOffset.Equals怎么用?C# DateTimeOffset.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeOffset
的用法示例。
在下文中一共展示了DateTimeOffset.Equals方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MostRecentlyUsed
/// <summary>
/// Initializes a new instance of the <see cref="MostRecentlyUsed"/> class.
/// </summary>
/// <param name="filePath">The full file path for the file.</param>
/// <param name="lastOpened">The last time the file was opened by the application.</param>
/// <exception cref="ArgumentNullException">
/// Thrown if <paramref name="filePath"/> is <see langword="null" />.
/// </exception>
/// <exception cref="ArgumentException">
/// Thrown if <paramref name="filePath"/> is an empty string.
/// </exception>
/// <exception cref="ArgumentException">
/// Thrown if <paramref name="lastOpened"/> is <see langword="DateTimeOffset.MinValue" /> or <see cref="DateTimeOffset.MaxValue"/>.
/// </exception>
public MostRecentlyUsed(string filePath, DateTimeOffset lastOpened)
{
{
Lokad.Enforce.Argument(() => filePath);
Lokad.Enforce.Argument(() => filePath, Lokad.Rules.StringIs.NotEmpty);
Lokad.Enforce.With<ArgumentException>(
!lastOpened.Equals(DateTimeOffset.MinValue),
Resources.Exceptions_Messages_ArgumentException);
Lokad.Enforce.With<ArgumentException>(
!lastOpened.Equals(DateTimeOffset.MaxValue),
Resources.Exceptions_Messages_ArgumentException);
}
m_FilePath = filePath;
m_LastOpened = lastOpened;
}
示例2: CompareTwoDateInDiffTZ
public void CompareTwoDateInDiffTZ ()
{
DateTimeOffset dt1 = new DateTimeOffset (2007, 12, 16, 15, 06, 00, new TimeSpan (1, 0, 0));
DateTimeOffset dt2 = new DateTimeOffset (2007, 12, 16, 9, 06, 00, new TimeSpan (-5, 0, 0));
DateTimeOffset dt3 = new DateTimeOffset (2007, 12, 16, 14, 06, 00, new TimeSpan (1, 0, 0));
object o = dt1;
Assert.IsTrue (dt1.CompareTo (dt2) == 0);
Assert.IsTrue (DateTimeOffset.Compare (dt1, dt2) == 0);
Assert.IsTrue (dt1 == dt2);
Assert.IsTrue (dt1.Equals (dt2));
Assert.IsFalse (dt1 == dt3);
Assert.IsTrue (dt1 != dt3);
Assert.IsFalse (dt1.EqualsExact (dt2));
Assert.IsTrue (dt1.CompareTo (dt3) > 0);
Assert.IsTrue (((IComparable)dt1).CompareTo (o) == 0);
}
示例3: EqualsObject
public void EqualsObject ()
{
DateTimeOffset offset1 = new DateTimeOffset ();
Assert.IsFalse (offset1.Equals (null), "null"); // found using Gendarme :)
Assert.IsTrue (offset1.Equals (offset1), "self");
DateTimeOffset offset2 = new DateTimeOffset (DateTime.Today);
Assert.IsFalse (offset1.Equals (offset2), "1!=2");
Assert.IsFalse (offset2.Equals (offset1), "2!=1");
}
示例4: Equals
public static void Equals(DateTimeOffset dateTimeOffset1, object obj, bool expectedEquals, bool expectedEqualsExact)
{
Assert.Equal(expectedEquals, dateTimeOffset1.Equals(obj));
if (obj is DateTimeOffset)
{
DateTimeOffset dateTimeOffset2 = (DateTimeOffset)obj;
Assert.Equal(expectedEquals, dateTimeOffset1.Equals(dateTimeOffset2));
Assert.Equal(expectedEquals, DateTimeOffset.Equals(dateTimeOffset1, dateTimeOffset2));
Assert.Equal(expectedEquals, dateTimeOffset1.GetHashCode().Equals(dateTimeOffset2.GetHashCode()));
Assert.Equal(expectedEqualsExact, dateTimeOffset1.EqualsExact(dateTimeOffset2));
Assert.Equal(expectedEquals, dateTimeOffset1 == dateTimeOffset2);
Assert.Equal(!expectedEquals, dateTimeOffset1 != dateTimeOffset2);
}
}
示例5: Initialize
/// <summary>
/// Initializes the builder. This resets all the
/// internal data structures and prepares them for
/// the reception of data for a new <see cref="TestSection"/>.
/// </summary>
/// <param name="name">The name of the test section.</param>
/// <param name="startTime">The start time.</param>
/// <exception cref="ArgumentNullException">
/// Thrown when <paramref name="name"/> is <see langword="null" />.
/// </exception>
/// <exception cref="ArgumentException">
/// Thrown when <paramref name="name"/> is an empty string.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when <paramref name="startTime"/> is equal to <see cref="DateTimeOffset.MinValue"/>.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when <paramref name="startTime"/> is equal to <see cref="DateTimeOffset.MaxValue"/>.
/// </exception>
public void Initialize(string name, DateTimeOffset startTime)
{
{
Lokad.Enforce.Argument(() => name);
Lokad.Enforce.Argument(() => name, Lokad.Rules.StringIs.NotEmpty);
Lokad.Enforce.With<ArgumentOutOfRangeException>(
!startTime.Equals(DateTimeOffset.MinValue),
Resources.Exceptions_Messages_ArgumentOutOfRange,
startTime);
Lokad.Enforce.With<ArgumentOutOfRangeException>(
!startTime.Equals(DateTimeOffset.MaxValue),
Resources.Exceptions_Messages_ArgumentOutOfRange,
startTime);
}
Clear();
m_Name = name;
m_StartTime = startTime;
}
示例6: AddWarningMessage
/// <summary>
/// Adds the warning message.
/// </summary>
/// <param name="time">The time on which the message was logged.</param>
/// <param name="warningMessage">The warning message.</param>
/// <exception cref="ArgumentNullException">
/// Thrown when <paramref name="warningMessage"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// Thrown when <paramref name="warningMessage"/> is an empty string.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when <paramref name="time"/> is equal to <see cref="DateTimeOffset.MinValue"/>.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when <paramref name="time"/> is equal to <see cref="DateTimeOffset.MaxValue"/>.
/// </exception>
/// <exception cref="CannotAddMessageToUninitializedTestSectionException">
/// Thrown when the <c>Initialize</c> method has not been called.
/// </exception>
public void AddWarningMessage(DateTimeOffset time, string warningMessage)
{
{
Lokad.Enforce.Argument(() => warningMessage);
Lokad.Enforce.Argument(() => warningMessage, Lokad.Rules.StringIs.NotEmpty);
Lokad.Enforce.With<ArgumentOutOfRangeException>(
!time.Equals(DateTimeOffset.MinValue),
Resources.Exceptions_Messages_ArgumentOutOfRange,
time);
Lokad.Enforce.With<ArgumentOutOfRangeException>(
!time.Equals(DateTimeOffset.MaxValue),
Resources.Exceptions_Messages_ArgumentOutOfRange,
time);
}
if (!WasInitialized)
{
throw new CannotAddMessageToUninitializedTestSectionException();
}
m_WarningMessages.Add(new DateBasedTestInformation(time, warningMessage));
}
示例7: ValidateDateNotDefault
public static void ValidateDateNotDefault(DateTimeOffset date, string fieldName)
{
if(date.Equals(DateTimeOffset.MinValue) || date.Equals(DateTimeOffset.MaxValue))
throw new OrderFieldBadFormatException(string.Format("{0} date value must have a valid logical date (not default value).", fieldName));
}