本文整理汇总了C#中PHP.Core.PhpArray.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# PhpArray.Clone方法的具体用法?C# PhpArray.Clone怎么用?C# PhpArray.Clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP.Core.PhpArray
的用法示例。
在下文中一共展示了PhpArray.Clone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompareArrays
/// <summary>
/// Compares two instances of <see cref="PhpArray"/>.
/// </summary>
/// <param name="comparer">The comparer.</param>
/// <param name="incomparable">Whether arrays are incomparable
/// (no difference is found before both arrays enters an infinite recursion).
/// Returns zero then.</param>
/// <include file='Doc/Common.xml' path='docs/method[@name="Compare(x,y)"]/*'/>
private static int CompareArrays(PhpArray x, PhpArray y, IComparer comparer, out bool incomparable)
{
Debug.Assert(x != null && y != null);
incomparable = false;
// if both operands point to the same internal dictionary:
if (object.ReferenceEquals(x.table, y.table))
return 0;
//
object child_x, child_y;
PhpArray array_x, array_y;
PhpArray sorted_x, sorted_y;
IEnumerator<KeyValuePair<IntStringKey, object>> iter_x, iter_y;
// if numbers of elements differs:
int result = x.Count - y.Count;
if (result != 0) return result;
// comparing with the same instance:
if (x == y) return 0;
// marks arrays as visited (will be always restored to false value before return):
x.Visited = true;
y.Visited = true;
// it will be more effective to implement OrderedHashtable.ToOrderedList method and use it here (in future version):
sorted_x = (PhpArray)x.Clone();
sorted_x.Sort(KeyComparer.ArrayKeys);
sorted_y = (PhpArray)y.Clone();
sorted_y.Sort(KeyComparer.ArrayKeys);
iter_x = sorted_x.GetEnumerator();
iter_y = sorted_y.GetEnumerator();
result = 0;
try
{
// compares corresponding elements (keys first values then):
while (iter_x.MoveNext())
{
iter_y.MoveNext();
// compares keys:
result = iter_x.Current.Key.CompareTo(iter_y.Current.Key);
if (result != 0) break;
// dereferences childs if they are references:
child_x = PhpVariable.Dereference(iter_x.Current.Value);
child_y = PhpVariable.Dereference(iter_y.Current.Value);
// compares values:
if ((array_x = child_x as PhpArray) != null)
{
if ((array_y = child_y as PhpArray) != null)
{
// at least one child has not been visited yet => continue with recursion:
if (!array_x.Visited || !array_y.Visited)
{
result = CompareArrays(array_x, array_y, comparer, out incomparable);
}
else
{
incomparable = true;
}
// infinity recursion has been detected:
if (incomparable) break;
}
else
{
// compares an array with a non-array:
array_x.CompareTo(child_y, comparer);
}
}
else
{
// compares unknown item with a non-array:
result = -comparer.Compare(child_y, child_x);
}
if (result != 0) break;
} // while
}
finally
{
x.Visited = false;
y.Visited = false;
}
return result;
//.........这里部分代码省略.........