|
#pragma warning disable CA1052 // Static holder types should be static
#if XUNIT_NULLABLE
#nullable enable
#else
// In case this is source-imported with global nullable enabled but no XUNIT_NULLABLE
#pragma warning disable CS8603
#endif
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace Xunit
{
/// <summary>
/// Contains various static methods that are used to verify that conditions are met during the
/// process of running tests.
/// </summary>
#if XUNIT_VISIBILITY_INTERNAL
internal
#else
public
#endif
partial class Assert
{
static readonly Type typeofDictionary = typeof(Dictionary<,>);
static readonly Type typeofHashSet = typeof(HashSet<>);
/// <summary>
/// Initializes a new instance of the <see cref="Assert"/> class.
/// </summary>
protected Assert() { }
/// <summary>Do not call this method.</summary>
[Obsolete("This is an override of Object.Equals(). Call Assert.Equal() instead.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public static new bool Equals(
object a,
object b)
{
throw new InvalidOperationException("Assert.Equals should not be used");
}
/// <summary>Do not call this method.</summary>
[Obsolete("This is an override of Object.ReferenceEquals(). Call Assert.Same() instead.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public static new bool ReferenceEquals(
object a,
object b)
{
throw new InvalidOperationException("Assert.ReferenceEquals should not be used");
}
/// <summary>
/// Safely perform <see cref="Type.GetGenericTypeDefinition"/>, returning <see langword="null"/> when the
/// type is not generic.
/// </summary>
/// <param name="type">The potentially generic type</param>
/// <returns>The generic type definition, when <paramref name="type"/> is generic; <see langword="null"/>, otherwise.</returns>
#if XUNIT_NULLABLE
static Type? SafeGetGenericTypeDefinition(Type? type)
#else
static Type SafeGetGenericTypeDefinition(Type type)
#endif
{
if (type == null)
return null;
if (!type.IsGenericType)
return null;
return type.GetGenericTypeDefinition();
}
}
}
|