Ejemplo n.º 1
0
                void WriteArray(PhpHashtable array)
                {
                    // [
                    Write(Tokens.ArrayOpen);

                    //
                    if (array.Count != 0)
                    {
                        bool bFirst = true;

                        var enumerator = array.GetFastEnumerator();
                        while (enumerator.MoveNext())
                        {
                            // ,
                            if (bFirst)
                            {
                                bFirst = false;
                            }
                            else
                            {
                                Write(Tokens.ItemsSeparatorString);
                            }

                            Debug.Assert(enumerator.CurrentKey.IsInteger);

                            // value
                            Accept(enumerator.CurrentValue);
                        }
                    }

                    // ]
                    Write(Tokens.ArrayClose);
                }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a <see cref="Dictionary{TKey, TValue}"/> from given <see cref="PhpArray"/>.
        /// </summary>
        public static Dictionary <TKey, TElement> ToDictionary <TKey, TElement>(this PhpHashtable source, Func <IntStringKey, TKey> keySelector, Func <PhpValue, TElement> elementSelector, IEqualityComparer <TKey> comparer)
        {
            var result = new Dictionary <TKey, TElement>(source.Count, comparer);

            var enumerator = source.GetFastEnumerator();

            while (enumerator.MoveNext())
            {
                var current = enumerator.Current;
                result[keySelector(current.Key)] = elementSelector(current.Value);
            }

            return(result);
        }