本文整理汇总了C#中Pchp.Core.PhpValue.DeepCopy方法的典型用法代码示例。如果您正苦于以下问题:C# PhpValue.DeepCopy方法的具体用法?C# PhpValue.DeepCopy怎么用?C# PhpValue.DeepCopy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pchp.Core.PhpValue
的用法示例。
在下文中一共展示了PhpValue.DeepCopy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: array_reduce
public static PhpValue array_reduce(Context ctx, [In, Out] PhpArray array, IPhpCallable function, PhpValue initialValue)
{
if (array == null)
{
//PhpException.ReferenceNull("array");
//return PhpValue.Null;
throw new ArgumentNullException(nameof(array));
}
//if (!PhpArgument.CheckCallback(function, caller, "function", 0, false)) return null;
if (array.Count == 0)
{
return initialValue;
}
PhpValue[] args = new PhpValue[] { initialValue.DeepCopy(), PhpValue.Null };
var iterator = array.GetFastEnumerator();
while (iterator.MoveNext())
{
var item = iterator.CurrentValue;
args[1] = item.IsAlias ? item : PhpValue.Create(item.EnsureAlias());
args[0] = function.Invoke(ctx, args);
// updates an item if it wasn't alias
if (!item.IsAlias)
{
iterator.CurrentValue = args[1].Alias.Value;
}
}
// dereferences the last returned value:
return args[0].GetValue();
}
示例2: SpliceInternal
/// <summary>
/// Implementation of <see cref="array_splice(PhpArray,int,int,object)"/> and <see cref="array_splice(PhpArray,int,int,object)"/>.
/// </summary>
/// <remarks>Whether to make a deep-copy of items in the replacement.</remarks>
internal static PhpArray SpliceInternal(PhpArray array, int offset, int length, PhpValue replacement, bool deepCopy)
{
Debug.Assert(array != null);
int count = array.Count;
// converts offset and length to interval [first,last]:
PhpMath.AbsolutizeRange(ref offset, ref length, count);
PhpArray result = new PhpArray(length);
// replacement is an array:
if (replacement.IsArray)
{
// provides deep copies:
IEnumerable<PhpValue> e = replacement.Array.Values;
if (deepCopy)
{
e = e.Select(Operators.DeepCopy);
}
// does replacement:
array.ReindexAndReplace(offset, length, e, result);
}
else if (replacement.IsNull)
{
// replacement is null:
array.ReindexAndReplace(offset, length, null, result);
}
else
{
// replacement is another type //
// creates a deep copy:
if (deepCopy) replacement = replacement.DeepCopy();
// does replacement:
array.ReindexAndReplace(offset, length, new[] { replacement }, result);
}
return result;
}
示例3: DeepCopy
/// <summary>
/// Gets copy of given value.
/// </summary>
public static PhpValue DeepCopy(PhpValue value) => value.DeepCopy();