Example #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);
        }
Example #2
0
        /// <summary>
        /// Converts a <see cref="Condition"/> to a <see cref="JsonCondition"/>.
        /// </summary>
        /// <param name="condition">The condition.</param>
        /// <returns>The converted condition.</returns>
        public static JsonCondition Parse(Condition condition)
        {
            var jcondition = new JsonCondition
            {
                Aggregate  = condition.Aggregate,
                Attribute  = condition.Attribute,
                Alias      = condition.Alias,
                Column     = condition.Column,
                EntityName = condition.EntityName,
                Extensions = condition.Extensions,
                Operator   = condition.Operator,
                UiHidden   = condition.UiHidden,
                UiName     = condition.UiName,
                UiType     = condition.UiType,
                Value      = condition.Value,
                Values     = condition.Values,
            };

            return(jcondition);
        }