Beispiel #1
0
        public static bool TryGetObj <T>(this IDictionary <string, object> data, string key, TryObjectBuild <T> builder, out T value)
        {
            object obj;

            if (data.TryGetValue(key, out obj) && obj is IDictionary <string, object> )
            {
                return(builder.Invoke(obj as IDictionary <string, object>, out value));
            }

            value = default(T);
            return(false);
        }
Beispiel #2
0
        public static bool TryGetObjArray <T>(this IDictionary <string, object> data, string key, TryObjectBuild <T> builder, out T[] value)
        {
            object obj;

            if (data.TryGetValue(key, out obj) && obj is IList <object> )
            {
                var list = (IList <object>)obj;
                value = new T[list.Count];

                for (int i = 0; i < list.Count; i++)
                {
                    if (!(list[i] is IDictionary <string, object> && builder.Invoke(list[i] as IDictionary <string, object>, out value[i])))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            value = null;
            return(false);
        }