/// <summary>
        /// Serialize the value into an JSON AST.
        /// </summary>
        /// <param name="type">The type to serialize from.</param>
        /// <param name="value">The value to serialize.</param>
        /// <returns>The JSON object that represents the serialized value.</returns>
        protected override JsonValue SerializeValue(Type type, object value)
        {
            var serializer = new JsonApiSerializer(ContractResolver, _fieldNamingStratgey);

            if (TypeHelper.IsEnumerable(type))
            {
                return(serializer.SerializeMany((IEnumerable)value));
            }

            return(serializer.SerializeEntity(value));
        }
示例#2
0
        /// <summary>
        /// Serialize the value into an JSON AST.
        /// </summary>
        /// <param name="type">The type to serialize from.</param>
        /// <param name="value">The value to serialize.</param>
        /// <returns>The JSON object that represents the serialized value.</returns>
        JsonValue SerializeContract(Type type, object value)
        {
            var serializer = new JsonApiSerializer(ContractResolver, FieldNamingStrategy);

            if (TypeHelper.IsEnumerable(type))
            {
                return(serializer.SerializeMany((IEnumerable)value));
            }

            return(serializer.SerializeEntity(value));
        }
示例#3
0
        /// <summary>
        /// Serialize the entity to a content string.
        /// </summary>
        /// <param name="entity">The entity to serialize.</param>
        /// <param name="serializerOptions">The serializer options.</param>
        /// <returns>The string that represents the serialized version of the entity.</returns>
        static string SerializeEntity(TEntity entity, JsonApiSerializerOptions serializerOptions)
        {
            var serializer = new JsonApiSerializer(serializerOptions);

            return(serializer.SerializeEntity(entity).Stringify());
        }
示例#4
0
        /// <summary>
        /// Serialize the entity to a content string.
        /// </summary>
        /// <param name="entity">The entity to serialize.</param>
        /// <param name="contractResolver">The resource contract resolver.</param>
        /// <returns>The string that represents the serialized version of the entity.</returns>
        static string SerializeEntity(TEntity entity, IContractResolver contractResolver)
        {
            var serializer = new JsonApiSerializer(contractResolver, new DasherizedFieldNamingStrategy());

            return(serializer.SerializeEntity(entity).Stringify());
        }
        /// <summary>
        /// Serialize the value into an JSON AST.
        /// </summary>
        /// <param name="type">The type to serialize from.</param>
        /// <param name="value">The value to serialize.</param>
        /// <returns>The JSON object that represents the serialized value.</returns>
        protected override JsonValue SerializeValue(Type type, object value)
        {
            var serializer = new JsonApiSerializer(ContractResolver, _fieldNamingStratgey);

            if (TypeHelper.IsEnumerable(type))
            {
                return serializer.SerializeMany((IEnumerable)value);
            }

            return serializer.SerializeEntity(value);
        }