Example #1
0
        /// <summary>
        /// Gets the properties of the given object.
        /// </summary>
        /// <param name="caller">Caller context.</param>
        /// <param name="obj"></param>
        /// <returns>Returns an associative array of defined object accessible non-static properties for the specified object in scope.
        /// If a property has not been assigned a value, it will be returned with a NULL value.</returns>
        public static PhpArray get_object_vars([ImportCallerClass] RuntimeTypeHandle caller, object obj)
        {
            Debug.Assert(!(obj is PhpAlias), "obj must be dereferenced");

            if (obj == null)
            {
                return(null); // not FALSE since PHP 5.3
            }
            else if (obj.GetType() == typeof(stdClass))
            {
                // optimization for stdClass:
                var arr = ((stdClass)obj).GetRuntimeFields();
                return((arr != null) ? arr.DeepCopy() : PhpArray.NewEmpty());
            }
            else
            {
                var result = PhpArray.NewEmpty();

                foreach (var pair in TypeMembersUtils.EnumerateVisibleInstanceFields(obj, caller))
                {
                    result.Add(pair.Key, pair.Value.DeepCopy());
                }

                return(result);
            }
        }
Example #2
0
        /// <summary>
        /// Instantiate new object's enumerator and advances its position to the first element.
        /// </summary>
        /// <returns><c>True</c> whether there is an first element.</returns>
        void InitObjectIteratorHelper()
        {
            Debug.Assert(_dobj != null);

            _dobjEnumerator = TypeMembersUtils.EnumerateVisibleInstanceFields(_dobj).GetEnumerator();   // we have to create new enumerator (or implement InstancePropertyIterator.Reset)
            _isValid        = _dobjEnumerator.MoveNext();
        }
Example #3
0
 public virtual long count()
 {
     if (_underlayingArray != null)
     {
         // array size
         return(_underlayingArray.Count);
     }
     else
     {
         // public (visible) instance properties + runtime fields
         return(TypeMembersUtils.EnumerateVisibleInstanceFields(_underlayingObject).LongCount());
     }
 }
Example #4
0
 public PhpArray getArrayCopy()
 {
     if (_underlayingArray != null)
     {
         // array size
         return(_underlayingArray.DeepCopy());
     }
     else
     {
         // public (visible) instance properties + runtime fields
         return(new PhpArray(TypeMembersUtils.EnumerateVisibleInstanceFields(_underlayingObject)));
     }
 }
Example #5
0
 public PhpFieldsEnumerator(object obj, RuntimeTypeHandle caller)
 {
     Debug.Assert(obj != null);
     _enumerator = TypeMembersUtils.EnumerateVisibleInstanceFields(obj, caller).GetEnumerator();
     _valid      = true;
 }