System.ComponentModel.Design.Serialization.ContextStack.Append C# (CSharp) Method

Append() public method

Appends an object to the end of the stack, rather than pushing it onto the top of the stack. This method allows a serializer to communicate with other serializers by adding contextual data that does not have to be popped in order. There is no way to remove an object that was appended to the end of the stack without popping all other objects.
public Append ( object context ) : void
context object
return void
        public void Append(object context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (_contextStack == null)
            {
                _contextStack = new ArrayList();
            }
            _contextStack.Insert(0, context);
        }

Usage Example

Exemplo n.º 1
0
        public void IntegrityTest()
        {
            ContextStack stack = new ContextStack();

            string one = "one";
            string two = "two";
            stack.Push(two);
            stack.Push(one);
            Assert.Same(one, stack[typeof(string)]);
            Assert.Same(one, stack[0]);
            Assert.Same(one, stack.Current);

            Assert.Same(one, stack.Pop());

            Assert.Same(two, stack[typeof(string)]);
            Assert.Same(two, stack[0]);
            Assert.Same(two, stack.Current);

            string three = "three";
            stack.Append(three);

            Assert.Same(two, stack[typeof(string)]);
            Assert.Same(two, stack[0]);
            Assert.Same(two, stack.Current);

            Assert.Same(two, stack.Pop());

            Assert.Same(three, stack[typeof(string)]);
            Assert.Same(three, stack[0]);
            Assert.Same(three, stack.Current);
            Assert.Same(three, stack.Pop());

            Assert.Null(stack.Pop());
            Assert.Null(stack.Current);
        }
All Usage Examples Of System.ComponentModel.Design.Serialization.ContextStack::Append