Exemple #1
0
        private static IEnumerable <KeyValuePair <string, T> > ApplyPath <T>(JToken root, string path)
        {
            // Children
            var children = SelectChildren <T>(root, path);

            foreach (var token in children)
            {
                // Token => T
                var value = (T)JsonFunctions.ConvertToken(token, typeof(T));

                // Tuple(path, value)
                yield return(new KeyValuePair <string, T>(token.Path, value));
            }
        }
Exemple #2
0
        /// <summary/>
        protected virtual void JObjectToRow(JObject o, IUpdatableRow row)
        {
            foreach (var c in row.Schema)
            {
                JToken token = null;
                object value = c.DefaultValue;

                // All fields are represented as columns
                //  Note: Each JSON row/payload can contain more or less columns than those specified in the row schema
                //  We simply update the row for any column that matches (and in any order).
                if (o.TryGetValue(c.Name, out token) && token != null)
                {
                    // Note: We simply delegate to Json.Net for all data conversions
                    //  For data conversions beyond what Json.Net supports, do an explicit projection:
                    //      ie: SELECT DateTime.Parse(datetime) AS datetime, ...
                    //  Note: Json.Net incorrectly returns null even for some non-nullable types (sbyte)
                    //      We have to correct this by using the default(T) so it can fit into a row value
                    value = JsonFunctions.ConvertToken(token, c.Type) ?? c.DefaultValue;
                }

                // Update
                row.Set <object>(c.Name, value);
            }
        }