예제 #1
0
 /// <summary>
 /// Serialize a list of members from the object.
 /// </summary>
 /// <param name="serializer">The serializer to utilize when serializing the values.</param>
 /// <param name="contract">The contract of the object to serialize the members from.</param>
 /// <param name="value">The value to serialize the members from.</param>
 /// <returns>The list of members that make up the object.</returns>
 IEnumerable <JsonMember> SerializeMembers(IJsonSerializer serializer, IContract contract, object value)
 {
     foreach (var field in contract.Fields.Where(ShouldSerializeField))
     {
         yield return(new JsonMember(_fieldNamingStrategy.GetName(field.Name), serializer.SerializeValue(field.GetValue(value))));
     }
 }
예제 #2
0
        /// <summary>
        /// Determine the members that are defined in the patch content.
        /// </summary>
        /// <param name="contract">The contract to use to return the members from.</param>
        /// <param name="jsonObject">The JSON object that defines the attributes & relationships.</param>
        /// <returns>The list of members that are defined in the patch content.</returns>
        IEnumerable <IMember> ExtractMembers(IContract contract, JsonObject jsonObject)
        {
            var dictionary = contract.Fields.ToDictionary(k => _fieldNamingStratgey.GetName(k.Name));

            if (jsonObject["attributes"] is JsonObject attributes)
            {
                foreach (var attribute in attributes.Members)
                {
                    if (dictionary.TryGetValue(attribute.Name, out IField member))
                    {
                        yield return(member);
                    }
                }
            }

            if (jsonObject["relationships"] is JsonObject relationships)
            {
                foreach (var relationship in relationships.Members)
                {
                    if (dictionary.TryGetValue(relationship.Name, out IField member))
                    {
                        yield return(member);
                    }
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Serialize a list of members from the object.
 /// </summary>
 /// <param name="serializer">The serializer to utilize when serializing the values.</param>
 /// <param name="type">The type of the object to serialize the members from.</param>
 /// <param name="value">The value to serialize the members from.</param>
 /// <returns>The list of members that make up the object.</returns>
 IEnumerable <JsonMember> SerializeMembers(IJsonSerializer serializer, Type type, object value)
 {
     foreach (var property in type.GetRuntimeProperties().Where(p => p.CanRead))
     {
         yield return(new JsonMember(_fieldNamingStrategy.GetName(property.Name), serializer.SerializeValue(property.GetValue(value))));
     }
 }