GME  13
ParentChain.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Linq;
00004 using System.Text;
00005 using GME.MGA;
00006 
00007 namespace CSGUI
00008 {
00009     public class ParentChainEnumerator : IEnumerator<IMgaObject>
00010     {
00011         #region IEnumerator<IMgaObject> Members
00012 
00013         IMgaObject original;
00014         public ParentChainEnumerator(IMgaObject obj)
00015         {
00016             this.original = obj;
00017         }
00018         public IMgaObject Current { get; set; }
00019 
00020         #endregion
00021 
00022         #region IDisposable Members
00023 
00024         public void Dispose()
00025         {
00026         }
00027 
00028         #endregion
00029 
00030         #region IEnumerator Members
00031 
00032         object System.Collections.IEnumerator.Current
00033         {
00034             get { return Current; }
00035         }
00036 
00037         public bool MoveNext()
00038         {
00039             if (Current == null)
00040             {
00041                 Current = original;
00042             }
00043             else
00044             {
00045                 GME.MGA.Meta.objtype_enum objType;
00046                 GME.MGA.MgaObject o;
00047                 Current.GetParent(out o, out objType);
00048                 Current = o;
00049             }
00050             return Current != null;
00051         }
00052 
00053         public void Reset()
00054         {
00055             Current = null;
00056         }
00057 
00058         #endregion
00059     }
00060 
00061     public class ParentChain : IEnumerable<IMgaObject>
00062     {
00063         IMgaObject obj;
00064         public ParentChain(IMgaObject obj)
00065         {
00066             this.obj = obj;
00067         }
00068         public IEnumerator<IMgaObject> GetEnumerator()
00069         {
00070             return new ParentChainEnumerator(obj);
00071         }
00072         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
00073         {
00074             return new ParentChainEnumerator(obj);
00075         }
00076     }
00077 }