Esempio n. 1
0
        /// <summary>
        /// 通知枚举成员结束.
        /// </summary>
        /// <param name="iw">带缩进输出者.</param>
        /// <param name="owner">欲查询成员的对象.</param>
        /// <param name="tp">类型.</param>
        /// <param name="options">成员选项. </param>
        /// <param name="handle">每个成员的处理过程. </param>
        /// <param name="context">环境对象. </param>
        /// <returns>若在开始枚举成员之前, 返回值表示是否允许枚举. 其他时候忽略.</returns>
        public bool NotifyForEachMemberEnd(IIndentedWriter iw, object owner, Type tp, IndentedWriterMemberOptions options, EventHandler <IndentedWriterMemberEventArgs> handle, IndentedWriterContext context)
        {
            bool rt = true;
            IndentedWriterForEachMemberNotify p = ForEachMemberEnd;

            if (null != p)
            {
                rt = p(iw, owner, tp, options, handle, context);
            }
            if (m_TypeOwners.Count > 0)
            {
                m_TypeOwners.RemoveAt(m_TypeOwners.Count - 1);
            }
            return(rt);
        }
Esempio n. 2
0
        /// <summary>
        /// 通知开始枚举成员.
        /// </summary>
        /// <param name="iw">带缩进输出者.</param>
        /// <param name="owner">欲查询成员的对象.</param>
        /// <param name="tp">类型.</param>
        /// <param name="options">成员选项. </param>
        /// <param name="handle">每个成员的处理过程. </param>
        /// <param name="context">环境对象. </param>
        /// <returns>若在开始枚举成员之前, 返回值表示是否允许枚举. 其他时候忽略.</returns>
        public bool NotifyForEachMemberBegin(IIndentedWriter iw, object owner, Type tp, IndentedWriterMemberOptions options, EventHandler <IndentedWriterMemberEventArgs> handle, IndentedWriterContext context)
        {
            bool rt = true;

            // check.
            if (null != owner && m_VisitOnce)
            {
                // 检查访问.
                if (m_VisitList.IndexOf(owner) >= 0)
                {
                    return(false);
                }
                m_VisitList.Add(owner);
            }
            if (null != tp && !tp.IsArray)
            {
                // 连续相同类型对象的最大数量.
                if (m_SameTypeGroupMax > 0 && null != owner)
                {
                    int cnt = 0;
                    for (int i = m_TypeOwners.Count - 1; i >= 0; --i)
                    {
                        KeyValuePair <Type, object> pr = m_TypeOwners[i];
                        if (null == pr.Value)
                        {
                            break;
                        }
                        if (tp.Equals(pr.Key))
                        {
                            ++cnt;
                            if (cnt >= m_SameTypeGroupMax)
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                // 相同类型的最大数量.
                if (m_SameTypeMax > 0)
                {
                    int cnt = 0;
                    foreach (KeyValuePair <Type, object> pr in m_TypeOwners)
                    {
                        if (tp.Equals(pr.Key))
                        {
                            ++cnt;
                            if (cnt >= m_SameTypeMax)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            // notify.
            m_TypeOwners.Add(new KeyValuePair <Type, object>(tp, owner));
            IndentedWriterForEachMemberNotify p = ForEachMemberBegin;

            if (null != p)
            {
                rt = p(iw, owner, tp, options, handle, context);
            }
            return(rt);
        }