Example #1
0
        /// <summary>
        ///     Sets the value.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="value">The value.</param>
        /// <param name="json">The json.</param>
        /// <exception cref="System.Exception">No Json backing object found!</exception>
        public void SetValue(JsonBackedObjectBase instance, string fieldName, T value, JToken json)
        {
            Dictionary <string, Tuple <JProperty, T> > dictionary = GetDictionary(instance);
            Tuple <JProperty, T> existing;

            if (dictionary.TryGetValue(fieldName, out existing))
            {
                JProperty originalToken = existing.Item1;
                originalToken.Value = json;
            }
            else
            {
                if (instance.JsonValue != null)
                {
                    var property = new JProperty(fieldName, json);
                    var owner    = (JObject)instance.JsonValue[r_Key];
                    owner.Add(property);
                    dictionary.Add(fieldName, new Tuple <JProperty, T>(property, value));
                }
                else
                {
                    throw new Exception("No Json backing object found!");
                }
            }
        }
Example #2
0
        /// <summary>
        ///     Evals the specified instance.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <returns>IReadOnlyDictionary&lt;System.String, T&gt;.</returns>
        public IReadOnlyDictionary <string, T> Eval(JsonBackedObjectBase instance)
        {
            Dictionary <string, Tuple <JProperty, T> > actual = GetDictionary(instance);

            r_Exposed.Clear();
            foreach (KeyValuePair <string, Tuple <JProperty, T> > item in actual)
            {
                r_Exposed.Add(item.Key, item.Value.Item2);
            }
            return(r_Exposed);
        }
Example #3
0
        /// <summary>
        ///     Evals the specified instance.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <returns>T.</returns>
        public T Eval(JsonBackedObjectBase instance)
        {
            T result;

            if (instance.TryGetValue(this, out result))
            {
                return(result);
            }
            result = Eval(instance.JsonValue);
            instance.SetValue(this, result);
            return(result);
        }
Example #4
0
        /// <summary>
        ///     Gets the dictionary.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <returns>Dictionary&lt;System.String, Tuple&lt;JToken, T&gt;&gt;.</returns>
        private Dictionary <string, Tuple <JProperty, T> > GetDictionary(JsonBackedObjectBase instance)
        {
            Dictionary <string, Tuple <JProperty, T> > result;

            if (instance.TryGetValue(this, out result))
            {
                return(result);
            }
            result = CreateDictionary(instance.JsonValue);
            instance.SetValue(this, result);
            return(result);
        }
Example #5
0
 /// <summary>
 ///     Evals the specified instance.
 /// </summary>
 /// <param name="instance">The instance.</param>
 /// <returns>IReadOnlyList&lt;T&gt;.</returns>
 public IReadOnlyList <T> Eval(JsonBackedObjectBase instance)
 {
     return(Eval(instance.JsonValue));
 }