本文整理汇总了C#中JToken.SingleOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# JToken.SingleOrDefault方法的具体用法?C# JToken.SingleOrDefault怎么用?C# JToken.SingleOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JToken
的用法示例。
在下文中一共展示了JToken.SingleOrDefault方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertPropertyValuesMatch
private bool AssertPropertyValuesMatch(JToken httpBody1, JToken httpBody2)
{
switch (httpBody1.Type)
{
case JTokenType.Array:
{
if (httpBody1.Count() != httpBody2.Count())
{
_reporter.ReportError(expected: httpBody1.Root, actual: httpBody2.Root);
return false;
}
for (var i = 0; i < httpBody1.Count(); i++)
{
if (httpBody2.Count() > i)
{
var isMatch = AssertPropertyValuesMatch(httpBody1[i], httpBody2[i]);
if (!isMatch)
{
break;
}
}
}
break;
}
case JTokenType.Object:
{
foreach (JProperty item1 in httpBody1)
{
var item2 = httpBody2.Cast<JProperty>().SingleOrDefault(x => x.Name == item1.Name);
if (item2 != null)
{
var isMatch = AssertPropertyValuesMatch(item1, item2);
if (!isMatch)
{
break;
}
}
else
{
_reporter.ReportError(expected: httpBody1.Root, actual: httpBody2.Root);
return false;
}
}
break;
}
case JTokenType.Property:
{
var httpBody2Item = httpBody2.SingleOrDefault();
var httpBody1Item = httpBody1.SingleOrDefault();
if (httpBody2Item == null && httpBody1Item == null)
{
return true;
}
if (httpBody2Item != null && httpBody1Item != null)
{
AssertPropertyValuesMatch(httpBody1Item, httpBody2Item);
}
else
{
_reporter.ReportError(expected: httpBody1.Root, actual: httpBody2.Root);
return false;
}
break;
}
case JTokenType.Integer:
case JTokenType.String:
{
if (!httpBody1.Equals(httpBody2))
{
_reporter.ReportError(expected: httpBody1.Root, actual: httpBody2.Root);
return false;
}
break;
}
default:
{
if (!JToken.DeepEquals(httpBody1, httpBody2))
{
_reporter.ReportError(expected: httpBody1.Root, actual: httpBody2.Root);
return false;
}
break;
}
}
return true;
}