Esempio n. 1
0
 public StateContainer(bool localAddressing, StateManager stateMan)
 {
     this.localAddressing = localAddressing;
     stateManager         = stateMan;
     nextKey = 0;
 }
Esempio n. 2
0
        internal static void SetManager(StateObject obj, StateManager container)
        {
            if (obj == null)
            {
                return;
            }

            obj.container = container;

            Type type = obj.GetType();

            FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
            for (int i = 0; i < fields.Length; i++)
            {
                Type fieldtype = fields[i].FieldType;
                if (typeof(IDataID).IsAssignableFrom(fieldtype))
                {
                    IDataID data = (IDataID)fields[i].GetValue(obj);
                    data.ResMan = container.ResourceManager;
                    fields[i].SetValue(obj, data);
                }
                else if (fieldtype.IsArray)
                {
                    Array array = (Array)fields[i].GetValue(obj);
                    for (int j = 0; j < array.Length; j++)
                    {
                        IDataID item = array.GetValue(j) as IDataID;
                        if (item != null)
                        {
                            ((IDataID)item).ResMan = container.ResourceManager;
                            array.SetValue(item, j);
                        }
                    }
                    fields[i].SetValue(obj, array);
                }
                //else if (fieldtype.IsSubclassOf(typeof(StateObject)))
                //{
                //    StateObject t = (StateObject)fields[i].GetValue(obj);
                //    SetManager(t, container);
                //    fields[i].SetValue(obj, t);
                //}
                else if (typeof(IStateLink).IsAssignableFrom(fieldtype))
                {
                    IStateLink t = (IStateLink)fields[i].GetValue(obj);
                    if (t != null)
                    {
                        t.Container = container;
                        fields[i].SetValue(obj, t);
                    }
                }
                else if (typeof(IStateLinkList).IsAssignableFrom(fieldtype))
                {
                    IStateLinkList t = (IStateLinkList)fields[i].GetValue(obj);
                    if (t != null)
                    {
                        t.Container = container;
                        for (int j = 0; j < t.List.Count; j++)
                        {
                            t.List[j].Container = container;
                        }
                        fields[i].SetValue(obj, t);
                    }
                }
                else if (!fieldtype.IsValueType && fieldtype != typeof(StateManager) &&
                         !fieldtype.IsArray && !fields[i].IsNotSerialized && fieldtype != typeof(String))
                {
                    throw new Exception("StateObject members must be ValueType, StateLinks or NonSerialized.");
                }
            }
        }