Beispiel #1
0
        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter"/> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            // convert from actual type to surrogate type

            var condition = value as Condition;

            if (condition != null)
            {
                var jcondition = JsonCondition.Parse(condition);
                serializer.Serialize(writer, jcondition);
            }

            if (value is Guid)
            {
                serializer.Serialize(writer, new JsonGuid {
                    Value = value.ToString()
                });
            }

            if (value is EntityFilters)
            {
                serializer.Serialize(writer, new JsonEntityFilters {
                    Value = (int)value
                });
            }

            CrmJsonConverter.Serialize(writer, value as DataCollection <string, object>, serializer);
            CrmJsonConverter.Serialize(writer, value as DataCollection <string, string>, serializer);
            CrmJsonConverter.Serialize(writer, value as DataCollection <Relationship, EntityCollection>, serializer);
            CrmJsonConverter.Serialize(writer, value as DataCollection <Relationship, QueryBase>, serializer);
            CrmJsonConverter.Serialize(writer, value as DataCollection <DeletedMetadataFilters, DataCollection <Guid> >, serializer);
            CrmJsonConverter.Serialize(writer, value as ICollection <object>, serializer);
        }
Beispiel #2
0
        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader"/> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>The object value.</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            // convert from surrogate type to actual type

            if (existingValue is Guid)
            {
                var id = serializer.Deserialize <JsonGuid>(reader);
                return(new Guid(id.Value));
            }

            if (existingValue is EntityFilters)
            {
                var filters = serializer.Deserialize <JsonEntityFilters>(reader);
                return((EntityFilters)filters.Value);
            }

            if (objectType == typeof(Condition))
            {
                var jcondition = serializer.Deserialize <JsonCondition>(reader);
                return(jcondition.ToCondition(Deserialize));
            }

            CrmJsonConverter.Deserialize(reader, existingValue as DataCollection <string, object>, serializer);
            CrmJsonConverter.Deserialize(reader, existingValue as DataCollection <string, string>, serializer);
            CrmJsonConverter.Deserialize(reader, existingValue as DataCollection <Relationship, EntityCollection>, serializer);
            CrmJsonConverter.Deserialize(reader, existingValue as DataCollection <Relationship, QueryBase>, serializer);
            CrmJsonConverter.Deserialize(reader, existingValue as DataCollection <DeletedMetadataFilters, DataCollection <Guid> >, serializer);
            CrmJsonConverter.Deserialize(reader, existingValue as ICollection <object>, serializer);

            return(existingValue);
        }