Beispiel #1
0
        static RecursiveDestinationClass MapRecursive(RecursiveSourceClass source, RecursiveDestinationClass dest)
        {
            var sourceStack = new Stack<RecursiveSourceClass>();
              var destStack = new Stack<RecursiveDestinationClass>();

              sourceStack.Push(source);
              destStack.Push(dest);

            Lbl:
              while (sourceStack.Count > 0)
              {
            var _source = sourceStack.Pop();
            var _dest = destStack.Pop();

            _dest.ID = _source.ID;

            if (_source.Child != null)
            {
              sourceStack.Push(_source.Child);
              destStack.Push(_dest.Child = new RecursiveDestinationClass());
            }

            if (_source.Foo != null)
            {

              var fooSourceStack = new Stack<SourceType>();
              var fooDestStack = new Stack<DestinationType>();

              fooSourceStack.Push(_source.Foo);
              fooDestStack.Push(null);

              while (fooSourceStack.Count > 0)
              {
            var _fooSource = fooSourceStack.Pop();

            var _fooDest = new DestinationType();

            _fooDest.ID = _fooSource.ID;
            _fooDest.Name = _fooSource.Name;

            if (_fooSource.Bar != null)
            {
              fooSourceStack.Push(_fooSource.Bar);
              fooDestStack.Push(_fooDest.Bar = new DestinationType());
            }

            if (_fooSource.Foo != null)
            {
              sourceStack.Push(_fooSource.Foo);
              destStack.Push(_fooDest.Foo = new RecursiveDestinationClass());
              goto Lbl;
            }

            _dest.Foo = _fooDest;

              }
            }

              }

              return dest;
        }