private static ObjectValueNode Rewrite( ObjectValueNode node, InputObjectType type, IVariableValueCollection variableValues) { if (node.Fields.Count == 0) { return(node); } if (node.Fields.Count == 1) { ObjectFieldNode value = node.Fields[0]; return(type.Fields.TryGetField(value.Name.Value, out InputField? field) && TryRewriteField(value, field, variableValues, out ObjectFieldNode? rewritten) ? node.WithFields(new[] { rewritten }) : node); } ObjectFieldNode[]? rewrittenItems = null; for (var i = 0; i < node.Fields.Count; i++) { ObjectFieldNode value = node.Fields[i]; if (type.Fields.TryGetField(value.Name.Value, out InputField? field) && TryRewriteField(value, field, variableValues, out ObjectFieldNode? rewritten)) { if (rewrittenItems is null) { rewrittenItems = new ObjectFieldNode[node.Fields.Count]; for (var j = 0; j < node.Fields.Count; j++) { rewrittenItems[j] = node.Fields[j]; } } rewrittenItems[i] = rewritten; } else if (rewrittenItems is not null) { rewrittenItems[i] = node.Fields[i]; } } if (rewrittenItems is not null) { return(node.WithFields(rewrittenItems)); } return(node); }
private static ObjectValueNode Rewrite( ObjectValueNode node, IVariableValueCollection variableValues) { if (node.Fields.Count == 0) { return(node); } if (node.Fields.Count == 1) { if (TryRewriteField(node.Fields[0], variableValues, out ObjectFieldNode? rewritten)) { return(node.WithFields(new[] { rewritten })); } return(node); } ObjectFieldNode[]? rewrittenItems = null; for (int i = 0; i < node.Fields.Count; i++) { if (TryRewriteField(node.Fields[i], variableValues, out ObjectFieldNode? rewritten)) { if (rewrittenItems is null) { rewrittenItems = new ObjectFieldNode[node.Fields.Count]; for (int j = 0; j < node.Fields.Count; j++) { rewrittenItems[j] = node.Fields[j]; } } rewrittenItems[i] = rewritten; } else if (rewrittenItems is { })