GetForeachEnumerator() public static method

Gets enumerator object for given value.
public static GetForeachEnumerator ( PhpValue value, bool aliasedValues, RuntimeTypeHandle caller ) : IPhpEnumerator
value PhpValue
aliasedValues bool
caller System.RuntimeTypeHandle
return IPhpEnumerator
コード例 #1
0
ファイル: Conversions.cs プロジェクト: windsOne/peachpie
 /// <summary>
 /// Creates <see cref="PhpArray"/> from object's properties.
 /// </summary>
 /// <param name="obj">Object instance.</param>
 /// <returns>Array containing given object properties keyed according to PHP specifications.</returns>
 public static PhpArray ClassToArray(object obj)
 {
     if (object.ReferenceEquals(obj, null))
     {
         return(PhpArray.NewEmpty());
     }
     else if (obj.GetType() == typeof(stdClass))
     {
         // special case,
         // object is stdClass, we can simply copy its runtime fields
         var runtime_fields = ((stdClass)obj).GetRuntimeFields();
         return((runtime_fields != null) ? runtime_fields.DeepCopy() : PhpArray.NewEmpty());
     }
     else
     {
         if (obj is IPhpConvertible conv)
         {
             return(ToArray(conv));
         }
         else if (obj is Array)
         {
             // [] -> array
             return(new PhpArray((Array)obj));
         }
         else if (obj is System.Collections.IEnumerable)
         {
             // the same behavior as foreach for CLR enumerators
             return(PhpArray.Create(Operators.GetForeachEnumerator((System.Collections.IEnumerable)obj)));
         }
         else
         {
             // obj -> array
             var arr = new PhpArray();
             TypeMembersUtils.InstanceFieldsToPhpArray(obj, arr);
             return(arr);
         }
     }
 }
コード例 #2
0
 public override IPhpEnumerator GetForeachEnumerator(ref PhpValue me, bool aliasedValues, RuntimeTypeHandle caller) => Operators.GetForeachEnumerator(me.Object, aliasedValues, caller);