I was wondering if any one could show me any other ways this method could be written, perhaps using LINQ?
private static bool CompareManyFoos(ManyFoos expected, ManyFoos actual)
{
IEnumerator<Foo> expFooAtor = expected.GetEnumerator();
IEnumerator<Foo> actFooAtor = actual.GetEnumerator();
while (expFooAtor.MoveNext())
{
if (actFooAtor.MoveNext())
{
if (!FoosEqual(expFooAtor.Current, actFooAtor.Current)) return false;
}
else
{
MissingFoo(expFooAtor.Current);
return false;
}
}
return true;
}
EDIT
I've had to patch up my sample code a bit as I made some mistakes, sorry all. This is the original method, I adapted my sample code from:
private static bool CompareXElementsChildXNodes(XElement expectedXElement, XElement actualXElement,
ref string message)
{
_itemLocator.LevelDown();
IEnumerator<XNode> expectedNodeRator = expectedXEle开发者_JAVA百科ment.Nodes().GetEnumerator();
IEnumerator<XNode> actualNodeRator = actualXElement.Nodes().GetEnumerator();
while (expectedNodeRator.MoveNext())
{
if (actualNodeRator.MoveNext())
{
if (CompareXNodes(expectedNodeRator.Current, actualNodeRator.Current, ref message))
{
_itemLocator.NextNode();
}
else
{
return false;
}
}
else
{
ExpectedXNodeActuallyMissing(expectedNodeRator.Current, ref message);
return false;
}
}
_itemLocator.LevelUp();
return true;
}
Perhaps SequenceEqual would be what you're looking for?
精彩评论