Beispiel #1
0
        public static List <T> ObjectsFromListFromFactory <T>(List <object> list, FactoryCreateMethod method)
        {
            List <T> result = new List <T>();

            if (list == null)
            {
                return(result);
            }

            foreach (var item in list)
            {
                IDictionary itemDict = item as IDictionary;
                string      id       = itemDict["id"].ToString();

                T         obj        = (T)method(id);
                IJSONable asJsonable = obj as IJSONable;
                if (asJsonable != null)
                {
                    asJsonable.FromDict(itemDict);
                    result.Add(obj);
                }
                else
                {
                    Debug.LogError("ObjectsFromListFromFactory parse error: " + id);
                }
            }

            return(result);
        }
Beispiel #2
0
        public static T ObjectFromDict <T>(IDictionary dict)
        {
            T newObj = (T)Activator.CreateInstance(typeof(T));

            if (dict != null && dict.Count > 0)
            {
                IJSONable asJsonable = newObj as IJSONable;
                asJsonable.FromDict(dict);
            }
            return(newObj);
        }
Beispiel #3
0
        public static Dictionary <string, T> ObjectsFromDictFromFactory <T>(IDictionary dict, FactoryCreateMethod method)
        {
            Dictionary <string, T> result = new Dictionary <string, T>();

            foreach (object e in dict.Keys)
            {
                string id = e.ToString();
                result[id] = (T)method(id);
                IJSONable asJsonable = result[id] as IJSONable;
                asJsonable.FromDict(dict[e] as IDictionary);
            }

            return(result);
        }