コード例 #1
0
        /// <summary>
        /// Dumps the properties with non-negative dump order.
        /// </summary>
        /// <param name="state">The current dump state.</param>
        /// <param name="statesWithRemainingProperties">The stack containing the states which have remaining properties.</param>
        /// <returns><c>true</c> if this is a dump tree leaf object, the current dump item is one of:
        /// <list type="bullet">
        /// <item><c>typeof(System.Object)</c></item><item><see cref="MemberInfo" /></item>
        /// <item>a delegate</item>
        /// <item>should not be dumped marked with <c>DumpAttribute(false)</c></item>
        /// </list>
        /// ; otherwise <c>false</c>.</returns>
        bool DumpedTopProperties(
            DumpState state,
            Stack <DumpState> statesWithRemainingProperties)
        {
            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }
            if (statesWithRemainingProperties == null)
            {
                throw new ArgumentNullException(nameof(statesWithRemainingProperties));
            }

            if (state.DumpedDelegate() ||
                state.DumpedMemberInfo() ||
                state.DumpedRootClass())
            {
                // we reached the root of the hierarchy, indent and while unwinding the stack dump the properties from each descending class
                state.Indent();
                state.Dispose();
                return(true);
            }

            var baseDumpState = state.GetBaseTypeDumpState();

            // 1. dump the properties of the base class with non-negative order
            DumpedTopProperties(baseDumpState, statesWithRemainingProperties);

            // 2. dump the non-negative order properties of the current class
            while (state.MoveNext())
            {
                // if we reached a negative order property,
                if (state.CurrentPropertyDumpAttribute.Order < 0)
                {
                    // put the state in the stack of states with remaining properties to be dumped
                    // and suspend the dumping at this inheritance level
                    statesWithRemainingProperties.Push(state);
                    return(false);
                }
                // otherwise dump the property
                state.DumpProperty();
            }

            // if we are here all properties have been dumped (no negative order properties)
            // and we do not need the state anymore.
            state.Dispose();

            return(false);
        }