本文整理汇总了C#中IEqualityComparer.?.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# IEqualityComparer.?.Equals方法的具体用法?C# IEqualityComparer.?.Equals怎么用?C# IEqualityComparer.?.Equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEqualityComparer
的用法示例。
在下文中一共展示了IEqualityComparer.?.Equals方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Equal
private static void Equal(JTokenAndSource expected, JTokenAndSource actual, IEqualityComparer<JValue> comparer, JsonAssertOptions options)
{
var expectedToken = expected?.JToken;
var actualToken = actual?.JToken;
if (expectedToken?.Type != actualToken?.Type)
{
var message = CreateMessage(expected, actual);
throw new AssertException(message);
}
CheckElementOrder(expected, actual, options);
if (expected?.JProperty?.Name != actual?.JProperty?.Name)
{
var message = CreateMessage(expected, actual);
throw new AssertException(message);
}
var expectedValue = expectedToken as JValue;
var actualValue = actualToken as JValue;
if (expectedValue != null || actualValue != null)
{
if (expectedValue == null || actualValue == null)
{
var message = CreateMessage(expected, actual);
throw new AssertException(message);
}
if (actualValue.HasValues)
{
var message = CreateMessage(expected, actual);
throw new AssertException(message);
}
var valueComparer = JValueComparer.GetFor(options);
if (valueComparer.Equals(expectedValue, actualValue))
{
return;
}
if (comparer?.Equals(expectedValue, actualValue) == true)
{
return;
}
else
{
var message = CreateMessage(expected, actual);
throw new AssertException(message);
}
}
for (int i = 0; i < Math.Max(expected?.Children.Count ?? 0, actual?.Children.Count ?? 0); i++)
{
var expectedChild = expected?.Children.ElementAtOrDefault(i);
var actualChild = actual?.Children.ElementAtOrDefault(i);
Equal(expectedChild, actualChild, comparer, options);
}
}