本文整理汇总了C#中PHP.Core.PhpArray.GetFastEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# PhpArray.GetFastEnumerator方法的具体用法?C# PhpArray.GetFastEnumerator怎么用?C# PhpArray.GetFastEnumerator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP.Core.PhpArray
的用法示例。
在下文中一共展示了PhpArray.GetFastEnumerator方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
public static object Search(object needle, PhpArray haystack, bool strict)
{
// result needn't to be deeply copied because it is a key of an array //
if (haystack == null)
{
PhpException.ArgumentNull("haystack");
return false;
}
// using operator ===:
if (strict)
{
using (var enumerator = haystack.GetFastEnumerator())
while (enumerator.MoveNext())
{
// dereferences value (because of StrictEquality operator):
object val = PhpVariable.Dereference(enumerator.CurrentValue);
if (Operators.StrictEquality(needle, val))
return enumerator.CurrentKey.Object;
}
}
else
{
// using operator ==:
using (var enumerator = haystack.GetFastEnumerator())
while (enumerator.MoveNext())
{
// comparator manages references well:
if (PhpComparer.CompareEq(needle, enumerator.CurrentValue))
return enumerator.CurrentKey.Object;
}
}
// not found:
return false;
}
示例2: Values
public static PhpArray Values(PhpArray array)
{
if (array == null)
{
PhpException.ArgumentNull("array");
return null;
}
// references are not dereferenced:
PhpArray result = new PhpArray(array.Count);
using (var enumerator = array.GetFastEnumerator())
while (enumerator.MoveNext())
result.AddToEnd(enumerator.CurrentValue);
// result is inplace deeply copied on return to PHP code:
result.InplaceCopyOnReturn = true;
return result;
}
示例3: Filter
public static PhpArray Filter(PHP.Core.Reflection.DTypeDesc _, PhpArray array)
{
var _result = new PhpArray();
using (var enumerator = array.GetFastEnumerator())
while (enumerator.MoveNext())
if (Core.Convert.ObjectToBoolean(enumerator.CurrentValue))
_result.Add(enumerator.CurrentKey, enumerator.CurrentValue);
return _result;
}
示例4: Keys
public static PhpArray Keys(PhpArray array, object searchValue, bool strict)
{
if (array == null)
{
PhpException.ArgumentNull("array");
return null;
}
PhpArray result = new PhpArray();
if (!strict)
{
using (var enumerator = array.GetFastEnumerator())
while (enumerator.MoveNext())
{
if (PhpComparer.CompareEq(enumerator.CurrentValue, searchValue))
result.AddToEnd(enumerator.CurrentKey.Object);
}
}
else
{
using (var enumerator = array.GetFastEnumerator())
while (enumerator.MoveNext())
{
if (Operators.StrictEquality(enumerator.CurrentValue, searchValue))
result.AddToEnd(enumerator.CurrentKey.Object);
}
}
// no need to make a deep copy since keys are immutable objects (strings, ints):
return result;
}
示例5: Unique
public static PhpArray Unique(PhpArray array, ArrayUniqueSortFlags sortFlags /*= String*/)
{
if (array == null)
{
PhpException.ArgumentNull("array");
return null;
}
IComparer comparer;
switch(sortFlags)
{
case ArrayUniqueSortFlags.Regular:
comparer = PhpComparer.Default; break;
case ArrayUniqueSortFlags.Numeric:
comparer = PhpNumericComparer.Default; break;
case ArrayUniqueSortFlags.String:
comparer = PhpStringComparer.Default; break;
case ArrayUniqueSortFlags.LocaleString:
default:
PhpException.ArgumentValueNotSupported("sortFlags", (int)sortFlags);
return null;
}
PhpArray result = new PhpArray(array.Count);
HashSet<object>/*!*/identitySet = new HashSet<object>(new ObjectEqualityComparer(comparer));
// get only unique values - first found
using (var enumerator = array.GetFastEnumerator())
while (enumerator.MoveNext())
{
if (identitySet.Add(PhpVariable.Dereference(enumerator.CurrentValue)))
result.Add(enumerator.Current);
}
result.InplaceCopyOnReturn = true;
return result;
}
示例6: ExpandFrame
/// <summary>
/// Adds additional arguments before arguments currently on stack.
/// Used for expanding 'use' parameters of lambda function.
/// </summary>
internal void ExpandFrame(PhpArray useParams)
{
if (useParams != null && useParams.Count > 0)
{
ArgCount += useParams.Count;
int new_top = Top + useParams.Count;
if (new_top > Items.Length) ResizeItems(new_top);
var stack_offset = new_top - 1;
using (var enumerator = useParams.GetFastEnumerator())
while (enumerator.MoveNext())
{
Items[stack_offset--] = enumerator.CurrentValue;
}
Top = new_top;
}
}
示例7: RedirectStreams
private static bool RedirectStreams(Process/*!*/ process, PhpArray/*!*/ descriptors, PhpArray/*!*/ pipes)
{
using (var descriptors_enum = descriptors.GetFastEnumerator())
while (descriptors_enum.MoveNext())
{
int desc_no = descriptors_enum.CurrentKey.Integer;
StreamAccessOptions access;
Stream stream;
switch (desc_no)
{
case 0: stream = process.StandardInput.BaseStream; access = StreamAccessOptions.Write; break;
case 1: stream = process.StandardOutput.BaseStream; access = StreamAccessOptions.Read; break;
case 2: stream = process.StandardError.BaseStream; access = StreamAccessOptions.Read; break;
default: Debug.Fail(null); return false;
}
object value = PhpVariable.Dereference(descriptors_enum.CurrentValue);
PhpResource resource;
PhpArray array;
if ((array = PhpArray.AsPhpArray(value)) != null)
{
if (!array.Contains(0))
{
// value must be either a resource or an array:
PhpException.Throw(PhpError.Warning, LibResources.GetString("descriptor_item_missing_qualifier", desc_no));
return false;
}
string qualifier = Core.Convert.ObjectToString(array[0]);
switch (qualifier)
{
case "pipe":
{
// mode is ignored (it's determined by the stream):
PhpStream php_stream = new NativeStream(stream, null, access, String.Empty, StreamContext.Default);
pipes.Add(desc_no, php_stream);
break;
}
case "file":
{
if (!array.Contains(1))
{
PhpException.Throw(PhpError.Warning, LibResources.GetString("descriptor_item_missing_file_name", desc_no));
return false;
}
if (!array.Contains(2))
{
PhpException.Throw(PhpError.Warning, LibResources.GetString("descriptor_item_missing_mode", desc_no));
return false;
}
string path = Core.Convert.ObjectToString(array[1]);
string mode = Core.Convert.ObjectToString(array[2]);
PhpStream php_stream = PhpStream.Open(path, mode, StreamOpenOptions.Empty, StreamContext.Default);
if (php_stream == null)
return false;
if (!ActivePipe.BeginIO(stream, php_stream, access, desc_no)) return false;
break;
}
default:
PhpException.Throw(PhpError.Warning, LibResources.GetString("invalid_handle_qualifier", qualifier));
return false;
}
}
else if ((resource = value as PhpResource) != null)
{
PhpStream php_stream = PhpStream.GetValid(resource);
if (php_stream == null) return false;
if (!ActivePipe.BeginIO(stream, php_stream, access, desc_no)) return false;
}
else
{
// value must be either a resource or an array:
PhpException.Throw(PhpError.Warning, LibResources.GetString("descriptor_item_not_array_nor_resource", desc_no));
return false;
}
}
return true;
}