/// <summary> /// Creates properties for the given <see cref="JsonContract"/>. /// </summary> /// <param name="type">The type to create properties for.</param> /// /// <param name="memberSerialization">The member serialization mode for the type.</param> /// <returns>Properties for the given <see cref="JsonContract"/>.</returns> protected virtual IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { List <MemberInfo> members = this.GetSerializableMembers(type); if (members == null) { throw new JsonSerializationException("Null collection of seralizable members returned."); } JsonPropertyCollection properties = new JsonPropertyCollection(type); foreach (MemberInfo member in members) { JsonProperty property = this.CreateProperty(member, memberSerialization); if (property != null) { properties.AddProperty(property); } } IList <JsonProperty> orderedProperties = properties.OrderBy(p => p.Order ?? -1).ToList(); return(orderedProperties); }
/// <summary> /// Creates the constructor parameters. /// </summary> /// <param name="constructor">The constructor to create properties for.</param> /// <param name="memberProperties">The type's member properties.</param> /// <returns>Properties for the given <see cref="ConstructorInfo"/>.</returns> protected virtual IList <JsonProperty> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties) { var constructorParameters = constructor.GetParameters(); JsonPropertyCollection parameterCollection = new JsonPropertyCollection(constructor.DeclaringType); foreach (ParameterInfo parameterInfo in constructorParameters) { JsonProperty matchingMemberProperty = memberProperties.GetClosestMatchProperty(parameterInfo.Name); // type must match as well as name if (matchingMemberProperty != null && matchingMemberProperty.PropertyType != parameterInfo.ParameterType) { matchingMemberProperty = null; } JsonProperty property = this.CreatePropertyFromConstructorParameter(matchingMemberProperty, parameterInfo); if (property != null) { parameterCollection.AddProperty(property); } } return(parameterCollection); }