/// <summary> /// Add any remaining fields defined in <paramref name="schema"/>. /// </summary> /// <param name="builder">Where to add any defined fields.</param> /// <param name="schema">JSON Schema that defines fields.</param> /// <param name="exclude">Fields not to include.</param> /// <returns>Modified <see cref="IFormBuilder{T}"/>.</returns> /// <remarks> /// See <see cref="FieldJson"/> for a description of JSON Schema extensions /// for defining your fields. /// </remarks> public static IFormBuilder <JObject> AddRemainingFields(this IFormBuilder <JObject> builder, JObject schema, IEnumerable <string> exclude = null) { var exclusions = (exclude == null ? new string[0] : exclude.ToArray()); var fields = new List <string>(); Fields(schema, null, fields); foreach (var field in fields) { if (!exclusions.Contains(field) && !builder.HasField(field)) { builder.Field(schema, field); } } return(builder); }
/// <summary> /// Add all fields not already added to the form. /// </summary> /// <param name="builder">Where to add fields.</param> /// <param name="exclude">Fields not to include.</param> /// <returns>Modified <see cref="IFormBuilder{T}"/>.</returns> /// <remarks> /// This will add all fields defined in your form that have not already been /// added if the fields are supported. /// </remarks> public static IFormBuilder <T> AddRemainingFields <T>(this IFormBuilder <T> builder, IEnumerable <string> exclude = null) where T : class { var exclusions = (exclude == null ? new string[0] : exclude.ToArray()); var paths = new List <string>(); FormBuilder <T> .FieldPaths(typeof(T), "", paths); foreach (var path in paths) { if (!exclusions.Contains(path) && !builder.HasField(path)) { builder.Field(new FieldReflector <T>(path)); } } return(builder); }