7 types derived from JsonNode
System.Text.Json (7)
2031 references to JsonNode
aspire (117)
Agents\DeprecatedMcpCommandScanner.cs (11)
65var config = JsonNode.Parse(content)?.AsObject();
120if (!config.TryGetPropertyValue(serversKey, out var serversNode) || serversNode is not JsonObject servers)
125if (!servers.TryGetPropertyValue("aspire", out var aspireNode) || aspireNode is not JsonObject aspire)
130if (!aspire.TryGetPropertyValue("args", out var argsNode) || argsNode is not JsonArray args)
152if (!config.TryGetPropertyValue(serversKey, out var mcpNode) || mcpNode is not JsonObject mcp)
157if (!mcp.TryGetPropertyValue("aspire", out var aspireNode) || aspireNode is not JsonObject aspire)
162if (!aspire.TryGetPropertyValue("command", out var commandNode) || commandNode is not JsonArray command)
222if (config.TryGetPropertyValue(serversKey, out var serversNode) &&
224servers.TryGetPropertyValue("aspire", out var aspireNode) &&
236if (config.TryGetPropertyValue(serversKey, out var mcpNode) &&
238mcp.TryGetPropertyValue("aspire", out var aspireNode) &&
Aspire.Cli.EndToEnd.Tests (22)
Aspire.Cli.Tests (98)
Aspire.Dashboard (29)
Aspire.Dashboard.Components.Tests (2)
Aspire.Dashboard.Tests (17)
Aspire.Hosting (82)
Dcp\JsonPatch.cs (22)
17internal static JsonArray Create(JsonNode? current, JsonNode? changed)
25internal static JsonNode? Apply(JsonNode? current, JsonArray patch)
27var result = current?.DeepClone();
29foreach (var operationNode in patch)
41var hasValue = operation.TryGetPropertyValue("value", out var value);
48private static void AddOperations(JsonNode? current, JsonNode? changed, string path, JsonArray operations)
50if (JsonNode.DeepEquals(current, changed))
68if (currentObject.TryGetPropertyValue(property.Key, out var currentValue))
105private static JsonObject CreateOperation(string operation, string path, JsonNode? value = null)
179private static JsonNode? ApplyOperation(JsonNode? current, string operation, string[] segments, bool hasValue, JsonNode? value)
200var parent = GetParent(current, segments);
218private static JsonNode GetParent(JsonNode? current, string[] segments)
220var parent = current ?? throw new JsonException("A JSON Patch path cannot traverse a null value.");
227JsonObject jsonObject when jsonObject.TryGetPropertyValue(segment, out var child) && child is not null => child,
237private static void ApplyToObject(JsonObject target, string operation, string propertyName, JsonNode? value)
260private static void ApplyToArray(JsonArray target, string operation, string indexText, JsonNode? value)
Pipelines\Internal\FileDeploymentStateManager.cs (28)
271protected override JsonNode? GetSectionState(JsonObject? state, string sectionName, bool includeLegacyState)
286var mergedSection = base.GetSectionState(state, sectionName, includeLegacyState)?.DeepClone();
350var legacySectionData = TryGetNestedPropertyValue(GetLegacyFallbackState(), sectionName);
381private static JsonObject? NormalizeSectionData(JsonNode? sectionData) =>
502JsonNode? legacyValue,
503JsonNode? savedValue,
515JsonNode? baseline,
517JsonNode? value,
525var baselinePropertyExists = baselineObject.TryGetPropertyValue(propertyName, out var baselineProperty);
526var savedPropertyExists = valueObject.TryGetPropertyValue(propertyName, out var valueProperty);
538if (baselineExists == savedExists && JsonNode.DeepEquals(baseline, value))
548private static JsonNode? ApplyChanges(JsonNode? latestValue, JsonNode? originalValue, JsonNode? savedValue)
560var originalPropertyExists = originalObject.TryGetPropertyValue(propertyName, out var originalProperty);
561var savedPropertyExists = savedObject.TryGetPropertyValue(propertyName, out var savedProperty);
562var latestPropertyExists = result.TryGetPropertyValue(propertyName, out var latestProperty);
583return JsonNode.DeepEquals(originalValue, savedValue)
587static (bool Exists, JsonNode? Value) ApplyPropertyChanges(
588JsonNode? latestValue,
590JsonNode? originalValue,
592JsonNode? savedValue,
595if (originalExists == savedExists && JsonNode.DeepEquals(originalValue, savedValue))
648if (!current.TryGetPropertyValue(segments[i], out var nextNode) ||
660private static void SetNestedNodeValue(JsonObject root, string path, JsonNode? value, bool valueExists)
667if (!current.TryGetPropertyValue(segment, out var nextNode) || nextNode is not JsonObject nextObject)
764JsonValue stateValue => JsonNode.Parse(stateValue.GetValue<string>())?.AsObject()
Aspire.Hosting.Azure (24)
Aspire.Hosting.Azure.EventHubs (5)
Aspire.Hosting.Azure.Kubernetes (2)
Aspire.Hosting.Azure.Sandboxes (3)
Aspire.Hosting.Azure.ServiceBus (5)
Aspire.Hosting.Azure.Tests (43)
Aspire.Hosting.CodeGeneration.Go (3)
Aspire.Hosting.CodeGeneration.Go.Tests (1)
Aspire.Hosting.CodeGeneration.Java (3)
Aspire.Hosting.CodeGeneration.Java.Tests (2)
Aspire.Hosting.CodeGeneration.Python (4)
Aspire.Hosting.CodeGeneration.Rust (1)
Aspire.Hosting.CodeGeneration.Rust.Tests (1)
Aspire.Hosting.CodeGeneration.TypeScript (10)
Aspire.Hosting.CodeGeneration.TypeScript.Tests (2)
Aspire.Hosting.Containers.Tests (10)
Aspire.Hosting.Dotnet.Tests (3)
Aspire.Hosting.DotnetTool.Tests (2)
Aspire.Hosting.Foundry.Tests (5)
Aspire.Hosting.Garnet.Tests (3)
Aspire.Hosting.Go.Tests (20)
Aspire.Hosting.Java.Tests (4)
Aspire.Hosting.JavaScript.Tests (17)
Aspire.Hosting.Kafka.Tests (1)
Aspire.Hosting.Keycloak.Tests (1)
Aspire.Hosting.Kubernetes (5)
Aspire.Hosting.Milvus.Tests (2)
Aspire.Hosting.MongoDB.Tests (3)
Aspire.Hosting.MySql.Tests (4)
Aspire.Hosting.Nats.Tests (3)
Aspire.Hosting.Oracle.Tests (4)
Aspire.Hosting.PostgreSQL.Tests (3)
Aspire.Hosting.Python.Tests (2)
Aspire.Hosting.Qdrant.Tests (2)
Aspire.Hosting.RabbitMQ.Tests (3)
Aspire.Hosting.Redis.Tests (17)
Aspire.Hosting.RemoteHost (78)
Ats\AtsCallbackProxyFactory.cs (14)
134var addMethod = jsonObjectType.GetMethod("Add", [typeof(string), typeof(JsonNode)]);
173private JsonNode? MarshalArg(object? value, Type declaredType)
241_invoker.InvokeAsync<JsonNode?>(callbackId, args, cancellationToken).GetAwaiter().GetResult();
247var result = _invoker.InvokeAsync<JsonNode?>(callbackId, args, cancellationToken).GetAwaiter().GetResult();
254var result = _invoker.InvokeAsync<JsonNode?>(callbackId, args, cancellationToken).GetAwaiter().GetResult();
261await _invoker.InvokeAsync<JsonNode?>(callbackId, args, cancellationToken).ConfigureAwait(false);
267var result = await _invoker.InvokeAsync<JsonNode?>(callbackId, args, cancellationToken).ConfigureAwait(false);
274var result = await _invoker.InvokeAsync<JsonNode?>(callbackId, args, cancellationToken).ConfigureAwait(false);
278private T? UnmarshalResult<T>(JsonNode? result, string callbackId)
373private void ApplyDtoWriteback(JsonNode? result, object?[] originalArgs, Type[] argTypes)
Ats\CapabilityDispatcher.cs (19)
21internal delegate Task<JsonNode?> CapabilityHandler(
183if (args == null || !args.TryGetPropertyValue("context", out var contextNode))
230if (args == null || !args.TryGetPropertyValue("context", out var contextNode))
246if (!args.TryGetPropertyValue("value", out var valueNode))
277return Task.FromResult<JsonNode?>(new JsonObject
308if (args == null || !args.TryGetPropertyValue("context", out var contextNode))
331if (args.TryGetPropertyValue(paramName, out var argNode))
428if (args != null && args.TryGetPropertyValue(paramName, out var argNode))
538public async Task<JsonNode?> InvokeAsync(string capabilityId, JsonObject? args)
623public JsonNode? Invoke(string capabilityId, JsonObject? args)
753JsonNode? argNode,
796JsonNode? argNode,
938private static bool IsRejectedEnumString(JsonNode? node, Type unionMemberType)
946private static string DescribeJsonNode(JsonNode? node)
1030if (!args.TryGetPropertyValue(name, out var node) || node is not JsonValue value)
1044if (args.TryGetPropertyValue(name, out var node) && node is JsonValue value)
1056if (args.TryGetPropertyValue(name, out var node) && node is JsonValue value)
1072if (!args.TryGetPropertyValue(name, out var node))
1099if (args.TryGetPropertyValue(name, out var node) && node is JsonObject obj)
Aspire.Hosting.RemoteHost.Tests (124)
CapabilityDispatcherTests.cs (85)
18CapabilityHandler handler = (args, handles) => Task.FromResult<JsonNode?>(JsonValue.Create("result"));
37dispatcher.Register("test/cap1@1", (_, _) => Task.FromResult<JsonNode?>(null));
38dispatcher.Register("test/cap2@1", (_, _) => Task.FromResult<JsonNode?>(null));
54return Task.FromResult<JsonNode?>(JsonValue.Create("success"));
70return Task.FromResult<JsonNode?>(null);
82dispatcher.Register("test/capability@1", (_, _) => Task.FromResult<JsonNode?>(JsonValue.Create(42)));
84var result = dispatcher.Invoke("test/capability@1", null);
109return Task.FromResult<JsonNode?>(null);
128return Task.FromResult<JsonNode?>(null);
146return Task.FromResult<JsonNode?>(null);
161Task.FromException<JsonNode?>(
186var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/testMethod", args);
198var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/withOptional", args);
210var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/withOptional", args);
265var nameResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/TestContextType.name", args);
266var countResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/TestContextType.count", args);
321var tokenResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/TestCancellationTokenContext.cancellationToken", getArgs);
327var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/canObserveCancellation", invokeArgs);
382var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/TestParentContextType.nestedContext", args);
399var operationResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/TestNestedContextType.operation", nestedArgs);
573var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/TestTypeWithMethods.calculateSum", args);
593var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/TestTypeWithMethods.processAsync", args);
613var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/TestTypeWithMethods.processValueTaskAsync", args);
625var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/asyncValueTaskWithResult", args);
670var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/withCallback", args);
736var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/withAsyncCallback", args);
748var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/syncInlineThreadProbe", null);
760var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/syncBackgroundThreadProbe", null);
772var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/taskBackgroundThreadProbe", null);
797var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/valueTaskBackgroundThreadProbe", null);
914var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/asyncWithResult", args);
943var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/sumArray", args);
955var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnArray", args);
975var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/acceptReadOnlyList", args);
988var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/acceptUnion", args);
1000var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/acceptUnion", args);
1018var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/acceptDtoUnion", args);
1030var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/acceptEnumStringUnion", args);
1042var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/acceptEnumStringUnion", args);
1083var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/acceptHandleUnion", args);
1135var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnMutableList", null);
1151var listResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnMutableList", null);
1162var result = dispatcher.Invoke("Aspire.Hosting/List.get", args);
1174var listResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnTypedMutableList", null);
1184var result = dispatcher.Invoke("Aspire.Hosting/List.get", args);
1197var listResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnMutableList", null);
1207var removeResult = dispatcher.Invoke("Aspire.Hosting/List.removeAt", removeArgs);
1217var lengthResult = dispatcher.Invoke("Aspire.Hosting/List.length", lengthArgs);
1230var listResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnMutableList", null);
1239var result = dispatcher.Invoke("Aspire.Hosting/List.length", args);
1252var listResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnMutableList", null);
1268var lengthResult = dispatcher.Invoke("Aspire.Hosting/List.length", lengthArgs);
1281var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnMutableDict", null);
1297var dictResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnMutableDict", null);
1308var result = dispatcher.Invoke("Aspire.Hosting/Dict.get", args);
1320var dictResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnTypedMutableDict", null);
1330var result = dispatcher.Invoke("Aspire.Hosting/Dict.get", args);
1342var dictResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnIntKeyMutableDict", null);
1352var result = dispatcher.Invoke("Aspire.Hosting/Dict.get", args);
1365var dictResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnMutableDict", null);
1375var removeResult = dispatcher.Invoke("Aspire.Hosting/Dict.remove", removeArgs);
1385var countResult = dispatcher.Invoke("Aspire.Hosting/Dict.count", countArgs);
1398var dictResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnMutableDict", null);
1408var hasResult = dispatcher.Invoke("Aspire.Hosting/Dict.has", hasArgs);
1419var hasResult2 = dispatcher.Invoke("Aspire.Hosting/Dict.has", hasArgs2);
1432var dictResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnMutableDict", null);
1441var result = dispatcher.Invoke("Aspire.Hosting/Dict.keys", args);
1457var dictResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnIntKeyMutableDict", null);
1466var result = dispatcher.Invoke("Aspire.Hosting/Dict.keys", args);
1481var dictResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnIntKeyMutableDict", null);
1501var dictResult = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnMutableDict", null);
1510var result = dispatcher.Invoke("Aspire.Hosting/Dict.count", args);
1527var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/acceptEnum", args);
1544var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/acceptEnum", args);
1561var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/returnEnum", args);
1578var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/acceptOptionalEnum", args);
1590var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/acceptOptionalEnum", new JsonObject());
1679var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/TestResourceWithProperties.color", args);
1720var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/TestResourceWithMethods.greet", args);
1737var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/TestResourceWithProperties.color", args);
1754var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/TestResourceWithProperties.name", args);
2097var result = dispatcher.Invoke("Aspire.Hosting.RemoteHost.Tests/findConnectionPropertyKey", args);
2136public List<(string CallbackId, JsonNode? Args)> Invocations { get; } = [];
2140public Task<TResult> InvokeAsync<TResult>(string callbackId, JsonNode? args, CancellationToken cancellationToken = default)
2148public Task InvokeAsync(string callbackId, JsonNode? args, CancellationToken cancellationToken = default)
Aspire.Hosting.Seq.Tests (3)
Aspire.Hosting.SqlServer.Tests (3)
Aspire.Hosting.Tests (68)
Dcp\JsonPatchTests.cs (16)
16var current = JsonNode.Parse("""{"unchanged":1,"removed":2,"replaced":"before"}""");
17var changed = JsonNode.Parse("""{"unchanged":1,"replaced":"after","added":true}""");
24Assert.True(JsonNode.DeepEquals(changed, JsonPatch.Apply(current, patch)));
38Assert.True(JsonNode.DeepEquals(changed, JsonPatch.Apply(current, patch)));
56var current = JsonNode.Parse(currentJson);
57var changed = JsonNode.Parse(changedJson);
62Assert.True(JsonNode.DeepEquals(changed, JsonPatch.Apply(current, patch)));
68var current = JsonNode.Parse("""{"a/b":{"m~n":"before"}}""");
69var changed = JsonNode.Parse("""{"a/b":{"m~n":"after"}}""");
76Assert.True(JsonNode.DeepEquals(changed, JsonPatch.Apply(current, patch)));
Aspire.Hosting.TestUtilities (14)
Aspire.Hosting.Valkey.Tests (2)
Aspire.Hosting.Yarp (3)
Aspire.TypeSystem (1)
ConfigurationSchemaGenerator (15)
ConfigurationSchemaGenerator.Tests (4)
dotnet-aot (4)
dotnet-user-jwts (1)
Infrastructure.Tests (5)
Microsoft.AspNetCore.JsonPatch.SystemTextJson (8)
Microsoft.AspNetCore.OpenApi (67)
Extensions\JsonNodeSchemaExtensions.cs (29)
60/// Note that this method targets <see cref="JsonNode"/> and not <see cref="OpenApiSchema"/> because it is
82/// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
84internal static void ApplyValidationAttributes(this JsonNode schema, IEnumerable<Attribute> validationAttributes)
170/// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
173internal static void ApplyDefaultValue(this JsonNode schema, object? defaultValue, JsonTypeInfo? jsonTypeInfo)
201/// Note that this method targets <see cref="JsonNode"/> and not <see cref="OpenApiSchema"/> because
205/// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
207internal static void ApplyPrimitiveFormats(this JsonNode schema, JsonSchemaExporterContext context)
220/// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
222internal static void ApplyRouteConstraints(this JsonNode schema, IEnumerable<IRouteConstraint> constraints)
296/// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
299internal static void ApplyParameterInfo(this JsonNode schema, ApiParameterDescription parameterDescription, JsonTypeInfo? jsonTypeInfo)
367enumArray.Add((JsonNode)name);
380&& schema[defaultKey] is JsonNode defaultNode
387var serialized = JsonSerializer.SerializeToNode(enumValue, jsonTypeInfo);
390schema[defaultKey] = (JsonNode)memberName;
425/// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
428internal static void MapPolymorphismOptionsToDiscriminator(this JsonNode schema, JsonSchemaExporterContext context, Func<JsonTypeInfo, string?> createSchemaReferenceId)
470/// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
473internal static void ApplySchemaReferenceId(this JsonNode schema, JsonSchemaExporterContext context, Func<JsonTypeInfo, string?> createSchemaReferenceId)
504/// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
506internal static bool WillBeComponentized(this JsonNode schema)
508return (schema[OpenApiConstants.SchemaId] is JsonNode schemaIdNode
540/// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
542internal static void ApplyNullabilityContextInfo(this JsonNode schema, JsonPropertyInfo propertyInfo)
588/// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
589internal static void PruneNullTypeForComponentizedTypes(this JsonNode schema)
614private static JsonSchemaType? MapJsonNodeToSchemaType(JsonNode? jsonNode)
630foreach (var node in jsonArray)
Services\Schemas\OpenApiSchemaService.cs (23)
236static JsonArray JsonArray(ReadOnlySpan<JsonNode> values)
240foreach (var value in values)
251var schemaAsJsonObject = CreateSchema(type);
276var rawNode = CreateSchema(type);
300&& refDefault is JsonNode defaultNode)
573private JsonNode CreateSchema(Type type)
578var schema = JsonSchemaExporter.GetJsonSchemaAsNode(_jsonSerializerOptions, underlyingType, _configuration);
582private static JsonNode ResolveReferences(JsonNode node, JsonNode rootSchema)
587private static JsonNode ResolveReferencesRecursive(JsonNode node, JsonNode rootSchema)
591if (jsonObject.TryGetPropertyValue(OpenApiConstants.RefKeyword, out var refNode) &&
600var resolvedNode = ResolveReference(refString, rootSchema);
622var processedValue = ResolveReferencesRecursive(property.Value, rootSchema);
639var processedValue = ResolveReferencesRecursive(jsonArray[i]!, rootSchema);
654private static JsonNode? ResolveReference(string refPath, JsonNode rootSchema)
671var currentNode = rootSchema;
728private static JsonNode EvaluateReferenceToken(string unescapedReferenceToken, JsonNode currentNode, string fullJsonPointer)
741if (!currentObject.TryGetPropertyValue(unescapedReferenceToken, out var referencedValue) ||
Microsoft.Extensions.AI (1)
Microsoft.Extensions.AI.Abstractions (73)
Functions\AIFunctionFactory.cs (7)
97/// or <see cref="JsonNode"/>, it is deserialized into the parameter type, utilizing <see cref="AIFunctionFactoryOptions.SerializerOptions"/> if provided,
178/// or <see cref="JsonNode"/>, it is deserialized into the parameter type, utilizing <paramref name="serializerOptions"/> if provided, or else
268/// or <see cref="JsonNode"/>, it is deserialized into the parameter type, utilizing <see cref="AIFunctionFactoryOptions.SerializerOptions"/> if provided,
357/// or <see cref="JsonNode"/>, it is deserialized into the parameter type, utilizing <paramref name="serializerOptions"/> if provided, or else
419/// <see cref="JsonDocument"/>, or <see cref="JsonNode"/>, it is deserialized directly. If the argument is anything else unknown,
460/// or <see cref="JsonNode"/>, it is deserialized into the parameter type, utilizing <see cref="AIFunctionFactoryOptions.SerializerOptions"/> if provided,
975JsonNode node => JsonSerializer.Deserialize(node, typeInfo),
Utilities\AIJsonUtilities.Schema.Create.cs (36)
122JsonNode parameterSchema = CreateJsonSchemaCore(
145(requiredProperties ??= []).Add((JsonNode)parameterSchemaName);
149JsonNode schema = new JsonObject();
200JsonNode schema = CreateJsonSchemaCore(type, parameter: null, nullabilityContext: null, description, hasDefaultValue, defaultValue, serializerOptions, inferenceOptions);
223private static JsonNode CreateJsonSchemaCore(
249JsonNode? defaultValueNode = defaultValue is not null
277JsonNode TransformSchemaNode(JsonSchemaExporterContext schemaExporterContext, JsonNode schema)
290if (parameter?.Name is not null && objSchema.TryGetPropertyValue(RefPropertyName, out JsonNode? paramName))
301objSchema[RefPropertyName] = (JsonNode)refUri;
328obj[TypePropertyName] = new JsonArray { (JsonNode)numericType, (JsonNode)"null" };
332obj[TypePropertyName] = (JsonNode)numericType;
343if (objSchema.TryGetPropertyValue(TypePropertyName, out JsonNode? typeKeyWord) &&
349objSchema[TypePropertyName] = new JsonArray { (JsonNode)typeValue, (JsonNode)"null" };
356objSchema.InsertAtStart(TypePropertyName, new JsonArray { (JsonNode)"string", (JsonNode)"null" });
364if (objSchema.TryGetPropertyValue(TypePropertyName, out JsonNode? typeKeyWord) &&
370objSchema[TypePropertyName] = new JsonArray { (JsonNode)typeValue, (JsonNode)"null" };
378JsonNode? defaultValueNode = JsonSerializer.SerializeToNode(defaultValue, ctx.TypeInfo);
385ConvertSchemaToObject(ref schema).InsertAtStart(DescriptionPropertyName, (JsonNode)localDescription);
391ConvertSchemaToObject(ref schema).InsertAtStart(SchemaPropertyName, (JsonNode)SchemaKeywordUri);
404static JsonObject ConvertSchemaToObject(ref JsonNode schema)
424void ApplyDataAnnotations(ref JsonNode schema, AIJsonSchemaCreateContext ctx)
497JsonNode? minNode = null;
498JsonNode? maxNode = null;
567JsonArray? requiredArray = requiredSchemaObj.TryGetPropertyValue(RequiredPropertyName, out JsonNode? existing) ?
580foreach (JsonNode? entry in requiredArray)
591requiredArray.Add((JsonNode)propertyName);
646JsonNode? notNode = obj[NotPropertyName];
716if (!schema.TryGetPropertyValue(TypePropertyName, out JsonNode? typeNode))
729foreach (JsonNode? entry in (JsonArray)typeNode)
786foreach (JsonNode? entry in typeArray)
821private static void InsertAtStart(this JsonObject jsonObject, string key, JsonNode value)
Utilities\AIJsonUtilities.Schema.Transform.cs (21)
32JsonNode? nodeSchema = JsonSerializer.SerializeToNode(schema, JsonContext.Default.JsonElement);
33JsonNode transformedSchema = TransformSchema(nodeSchema, transformOptions);
37private static JsonNode TransformSchema(JsonNode? schema, AIJsonSchemaTransformOptions transformOptions)
43private static JsonNode TransformSchemaCore(JsonNode? schema, AIJsonSchemaTransformOptions transformOptions, List<string>? path)
50schema = new JsonObject { [NotPropertyName] = (JsonNode)true };
68if (schemaObj.TryGetPropertyValue(PropertiesPropertyName, out JsonNode? props) && props is JsonObject propsObj)
82if (schemaObj.TryGetPropertyValue(ItemsPropertyName, out JsonNode? itemsSchema))
89if (schemaObj.TryGetPropertyValue(AdditionalPropertiesPropertyName, out JsonNode? additionalProps) &&
97if (schemaObj.TryGetPropertyValue(NotPropertyName, out JsonNode? notSchema))
108if (schemaObj.TryGetPropertyValue(combinatorKeyword, out JsonNode? combinatorSchema) && combinatorSchema is JsonArray combinatorArray)
114JsonNode element = TransformSchemaCore(combinatorArray[i], transformOptions, path);
130schemaObj[AdditionalPropertiesPropertyName] = (JsonNode)false;
138requiredProps.Add((JsonNode)prop.Key);
145schemaObj.TryGetPropertyValue(TypePropertyName, out JsonNode? typeSchema) &&
151foreach (JsonNode? typeNode in typeArray)
172schemaObj["type"] = (JsonNode)foundType;
173schemaObj["nullable"] = (JsonNode)true;
178schemaObj.TryGetPropertyValue(DefaultPropertyName, out JsonNode? defaultSchema))
180string? description = schemaObj.TryGetPropertyValue(DescriptionPropertyName, out JsonNode? descriptionSchema) ? descriptionSchema?.GetValue<string>() : null;
Microsoft.Extensions.AI.Abstractions.Tests (40)
Utilities\AIJsonUtilitiesTests.cs (10)
100case null when property.PropertyType == typeof(Func<AIJsonSchemaCreateContext, JsonNode, JsonNode>):
101Func<AIJsonSchemaCreateContext, JsonNode, JsonNode> transformer = static (context, schema) => (JsonNode)true;
682JsonNode? schemaAsNode = JsonSerializer.SerializeToNode(schema, options);
695JsonNode? serializedValue = JsonSerializer.SerializeToNode(testData.Value, testData.Type, options);
1830schemaObj.Add("myAwesomeKeyword", (JsonNode)42);
1846if (schemaObj.TryGetPropertyValue("properties", out JsonNode? props))
1853if (schemaObj.TryGetPropertyValue("type", out JsonNode? type) && type is JsonArray typeArray)
Microsoft.Extensions.AI.Evaluation.Quality (5)
Microsoft.Extensions.AI.Evaluation.Safety (4)
Microsoft.Extensions.AI.Integration.Tests (5)
Microsoft.Extensions.AI.OpenAI (1)
Microsoft.Extensions.AI.OpenAI.Tests (1)
Microsoft.Extensions.AI.Tests (3)
Microsoft.ML.AutoML (12)
Microsoft.ML.AutoML.SourceGenerator (5)
Microsoft.NET.Build.Containers (17)
Microsoft.NET.Build.Tasks (9)
Microsoft.NETCore.Platforms (2)
Microsoft.TemplateEngine.Cli (52)
JExtensions.cs (28)
19internal static string? ToString(this JsonNode? token, string? key)
41JsonNode? element = GetPropertyCaseInsensitive(obj, key);
50internal static bool TryGetValue(this JsonNode? token, string? key, out JsonNode? result)
75internal static bool TryParseBool(this JsonNode token, out bool result)
96internal static bool ToBool(this JsonNode? token, string? key = null, bool defaultValue = false)
98if (!token.TryGetValue(key, out JsonNode? checkToken))
111internal static int ToInt32(this JsonNode? token, string? key = null, int defaultValue = 0)
128JsonNode? element = GetPropertyCaseInsensitive(obj, key);
137internal static T ToEnum<T>(this JsonNode token, string? key = null, T defaultValue = default)
149internal static Guid ToGuid(this JsonNode token, string? key = null, Guid defaultValue = default)
160internal static IEnumerable<KeyValuePair<string, JsonNode?>> PropertiesOf(this JsonNode? token, string? key = null)
164return Array.Empty<KeyValuePair<string, JsonNode?>>();
169JsonNode? element = GetPropertyCaseInsensitive(currentJObj, key);
172return Array.Empty<KeyValuePair<string, JsonNode?>>();
180internal static T? Get<T>(this JsonNode? token, string? key)
181where T : JsonNode
188JsonNode? res = GetPropertyCaseInsensitive(obj, key);
192internal static IReadOnlyList<string> ArrayAsStrings(this JsonNode? token, string? propertyName = null)
206foreach (JsonNode? item in arr)
222return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
226internal static void WriteObject(this IPhysicalFileSystem fileSystem, string path, JsonNode obj)
233internal static bool TryParse(this string arg, out JsonNode? token)
237token = JsonNode.Parse(arg, null, DocOptions);
247private static bool TryParseInt(this JsonNode token, out int result)
267private static JsonNode? GetPropertyCaseInsensitive(JsonObject obj, string key)
269if (obj.TryGetPropertyValue(key, out JsonNode? result))
PostActionProcessors\AddJsonPropertyPostActionProcessor.cs (10)
152JsonNode? newJsonContent = AddElementToJson(
173private static JsonNode? AddElementToJson(IPhysicalFileSystem fileSystem, string targetJsonFile, string? propertyPath, string propertyPathSeparator, string newJsonPropertyName, string newJsonPropertyValue, IPostAction action)
176JsonNode? jsonContent = JsonNode.Parse(fileContent, nodeOptions: null, documentOptions: DeserializerOptions);
190JsonNode? parentProperty = FindJsonNode(jsonContent, propertyPath, propertyPathSeparator, createPath);
200parentProperty[newJsonPropertyName] = JsonNode.Parse(newJsonPropertyValue);
210private static JsonNode? FindJsonNode(JsonNode content, string? nodePath, string pathSeparator, bool createPath)
219JsonNode? node = content;
228JsonNode? childNode = node[property];
Microsoft.TemplateEngine.Edge (80)
parent\Shared\JExtensions.cs (57)
27internal static string? ToString(this JsonNode? token, string? key)
49JsonNode? element = GetPropertyCaseInsensitive(obj, key);
63internal static bool TryGetValue(this JsonNode? token, string? key, out JsonNode? result)
88internal static bool TryParseBool(this JsonNode token, out bool result)
109internal static bool ToBool(this JsonNode? token, string? key = null, bool defaultValue = false)
111if (!token.TryGetValue(key, out JsonNode? checkToken))
124internal static bool TryParseInt(this JsonNode token, out int result)
144internal static int ToInt32(this JsonNode? token, string? key = null, int defaultValue = 0)
161JsonNode? element = GetPropertyCaseInsensitive(obj, key);
170internal static T ToEnum<T>(this JsonNode token, string? key = null, T defaultValue = default, bool ignoreCase = false)
182internal static Guid ToGuid(this JsonNode token, string? key = null, Guid defaultValue = default)
200JsonNode? token = jObject.Get<JsonNode>(propertyName);
208internal static IEnumerable<KeyValuePair<string, JsonNode?>> PropertiesOf(this JsonNode? token, string? key = null)
217JsonNode? element = GetPropertyCaseInsensitive(obj, key);
236private static IReadOnlyList<KeyValuePair<string, JsonNode?>> GetObjectProperties(JsonObject obj)
256/// when the internal dictionary has not yet been initialized, so <see cref="JsonNode.ToJsonString"/> is
260private static List<KeyValuePair<string, JsonNode?>> GetObjectPropertiesViaDocument(JsonObject obj)
263var result = new List<KeyValuePair<string, JsonNode?>>();
268var property = new KeyValuePair<string, JsonNode?>(prop.Name, ParseJsonNode(prop.Value.GetRawText()));
282internal static T? Get<T>(this JsonNode? token, string? key)
283where T : JsonNode
290JsonNode? res = GetPropertyCaseInsensitive(obj, key);
294internal static IReadOnlyDictionary<string, string> ToStringDictionary(this JsonNode token, StringComparer? comparer = null, string? propertyName = null)
315internal static IReadOnlyDictionary<string, JsonNode> ToJsonNodeDictionary(this JsonNode token, StringComparer? comparer = null, string? propertyName = null)
317Dictionary<string, JsonNode> result = new(comparer ?? StringComparer.Ordinal);
334internal static IReadOnlyDictionary<string, string> ToJsonNodeStringDictionary(this JsonNode token, StringComparer? comparer = null, string? propertyName = null)
349internal static TemplateParameterPrecedence ToTemplateParameterPrecedence(this JsonNode jObject, string? key)
351if (!jObject.TryGetValue(key, out JsonNode? checkToken))
364internal static IReadOnlyList<string> ArrayAsStrings(this JsonNode? token, string? propertyName = null)
378foreach (JsonNode? item in arr)
389internal static IReadOnlyList<Guid> ArrayAsGuids(this JsonNode? token, string? propertyName = null)
403foreach (JsonNode? item in arr)
417internal static IEnumerable<T> Items<T>(this JsonNode? token, string? propertyName = null)
418where T : JsonNode
430foreach (JsonNode? item in arr)
444return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
453return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
463internal static IReadOnlyList<string> JTokenStringOrArrayToCollection(this JsonNode? token, IReadOnlyList<string> defaultSet)
503internal static bool TryGetValueCaseInsensitive(this JsonObject obj, string key, out JsonNode? result)
513internal static JsonNode? GetPropertyCaseInsensitive(JsonObject obj, string key)
518if (obj.TryGetPropertyValue(key, out JsonNode? result))
546private static JsonNode? GetPropertyCaseInsensitiveViaDocument(JsonObject obj, string key)
551JsonNode? result = null;
552JsonNode? caseInsensitiveResult = null;
576return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
583internal static JsonNode? ParseJsonNode(string json)
585return JsonNode.Parse(json, null, DocOptions);
599return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
608return (JsonObject?)JsonNode.Parse(source.ToJsonString(), null, DocOptions)
624&& target.TryGetPropertyValue(property.Key, out JsonNode? targetNode)
635foreach (var item in sourceArr)
637targetArr.Add(item != null ? JsonNode.Parse(item.ToJsonString()) : null);
644? JsonNode.Parse(property.Value.ToJsonString())
Microsoft.TemplateEngine.Orchestrator.RunnableProjects (87)
ConfigModel\TemplateConfigModel.cs (8)
158JsonNode? globalCustomConfigData = JExtensions.GetPropertyCaseInsensitive(source, nameof(GlobalCustomOperations));
165IReadOnlyDictionary<string, JsonNode> allSpecialOpsConfig = source.ToJsonNodeDictionary(StringComparer.OrdinalIgnoreCase, nameof(SpecialCustomOperations));
168foreach (KeyValuePair<string, JsonNode> globConfigKeyValue in allSpecialOpsConfig)
171JsonNode globData = globConfigKeyValue.Value;
194obj.TryGetValue(nameof(TemplateConstraintInfo.Args), out JsonNode? args);
542IReadOnlyDictionary<string, JsonNode> templateDefinedForms = source.ToJsonNodeDictionary(StringComparer.OrdinalIgnoreCase, nameof(Forms));
544foreach (KeyValuePair<string, JsonNode> form in templateDefinedForms)
554private static IReadOnlyDictionary<string, IBaselineInfo> BaselineInfoFromJObject(IEnumerable<KeyValuePair<string, JsonNode?>> baselineProperties)
parent\Shared\JExtensions.cs (57)
27internal static string? ToString(this JsonNode? token, string? key)
49JsonNode? element = GetPropertyCaseInsensitive(obj, key);
63internal static bool TryGetValue(this JsonNode? token, string? key, out JsonNode? result)
88internal static bool TryParseBool(this JsonNode token, out bool result)
109internal static bool ToBool(this JsonNode? token, string? key = null, bool defaultValue = false)
111if (!token.TryGetValue(key, out JsonNode? checkToken))
124internal static bool TryParseInt(this JsonNode token, out int result)
144internal static int ToInt32(this JsonNode? token, string? key = null, int defaultValue = 0)
161JsonNode? element = GetPropertyCaseInsensitive(obj, key);
170internal static T ToEnum<T>(this JsonNode token, string? key = null, T defaultValue = default, bool ignoreCase = false)
182internal static Guid ToGuid(this JsonNode token, string? key = null, Guid defaultValue = default)
200JsonNode? token = jObject.Get<JsonNode>(propertyName);
208internal static IEnumerable<KeyValuePair<string, JsonNode?>> PropertiesOf(this JsonNode? token, string? key = null)
217JsonNode? element = GetPropertyCaseInsensitive(obj, key);
236private static IReadOnlyList<KeyValuePair<string, JsonNode?>> GetObjectProperties(JsonObject obj)
256/// when the internal dictionary has not yet been initialized, so <see cref="JsonNode.ToJsonString"/> is
260private static List<KeyValuePair<string, JsonNode?>> GetObjectPropertiesViaDocument(JsonObject obj)
263var result = new List<KeyValuePair<string, JsonNode?>>();
268var property = new KeyValuePair<string, JsonNode?>(prop.Name, ParseJsonNode(prop.Value.GetRawText()));
282internal static T? Get<T>(this JsonNode? token, string? key)
283where T : JsonNode
290JsonNode? res = GetPropertyCaseInsensitive(obj, key);
294internal static IReadOnlyDictionary<string, string> ToStringDictionary(this JsonNode token, StringComparer? comparer = null, string? propertyName = null)
315internal static IReadOnlyDictionary<string, JsonNode> ToJsonNodeDictionary(this JsonNode token, StringComparer? comparer = null, string? propertyName = null)
317Dictionary<string, JsonNode> result = new(comparer ?? StringComparer.Ordinal);
334internal static IReadOnlyDictionary<string, string> ToJsonNodeStringDictionary(this JsonNode token, StringComparer? comparer = null, string? propertyName = null)
349internal static TemplateParameterPrecedence ToTemplateParameterPrecedence(this JsonNode jObject, string? key)
351if (!jObject.TryGetValue(key, out JsonNode? checkToken))
364internal static IReadOnlyList<string> ArrayAsStrings(this JsonNode? token, string? propertyName = null)
378foreach (JsonNode? item in arr)
389internal static IReadOnlyList<Guid> ArrayAsGuids(this JsonNode? token, string? propertyName = null)
403foreach (JsonNode? item in arr)
417internal static IEnumerable<T> Items<T>(this JsonNode? token, string? propertyName = null)
418where T : JsonNode
430foreach (JsonNode? item in arr)
444return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
453return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
463internal static IReadOnlyList<string> JTokenStringOrArrayToCollection(this JsonNode? token, IReadOnlyList<string> defaultSet)
503internal static bool TryGetValueCaseInsensitive(this JsonObject obj, string key, out JsonNode? result)
513internal static JsonNode? GetPropertyCaseInsensitive(JsonObject obj, string key)
518if (obj.TryGetPropertyValue(key, out JsonNode? result))
546private static JsonNode? GetPropertyCaseInsensitiveViaDocument(JsonObject obj, string key)
551JsonNode? result = null;
552JsonNode? caseInsensitiveResult = null;
576return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
583internal static JsonNode? ParseJsonNode(string json)
585return JsonNode.Parse(json, null, DocOptions);
599return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
608return (JsonObject?)JsonNode.Parse(source.ToJsonString(), null, DocOptions)
624&& target.TryGetPropertyValue(property.Key, out JsonNode? targetNode)
635foreach (var item in sourceArr)
637targetArr.Add(item != null ? JsonNode.Parse(item.ToJsonString()) : null);
644? JsonNode.Parse(property.Value.ToJsonString())
Microsoft.TemplateEngine.Utils (57)
parent\Shared\JExtensions.cs (57)
27internal static string? ToString(this JsonNode? token, string? key)
49JsonNode? element = GetPropertyCaseInsensitive(obj, key);
63internal static bool TryGetValue(this JsonNode? token, string? key, out JsonNode? result)
88internal static bool TryParseBool(this JsonNode token, out bool result)
109internal static bool ToBool(this JsonNode? token, string? key = null, bool defaultValue = false)
111if (!token.TryGetValue(key, out JsonNode? checkToken))
124internal static bool TryParseInt(this JsonNode token, out int result)
144internal static int ToInt32(this JsonNode? token, string? key = null, int defaultValue = 0)
161JsonNode? element = GetPropertyCaseInsensitive(obj, key);
170internal static T ToEnum<T>(this JsonNode token, string? key = null, T defaultValue = default, bool ignoreCase = false)
182internal static Guid ToGuid(this JsonNode token, string? key = null, Guid defaultValue = default)
200JsonNode? token = jObject.Get<JsonNode>(propertyName);
208internal static IEnumerable<KeyValuePair<string, JsonNode?>> PropertiesOf(this JsonNode? token, string? key = null)
217JsonNode? element = GetPropertyCaseInsensitive(obj, key);
236private static IReadOnlyList<KeyValuePair<string, JsonNode?>> GetObjectProperties(JsonObject obj)
256/// when the internal dictionary has not yet been initialized, so <see cref="JsonNode.ToJsonString"/> is
260private static List<KeyValuePair<string, JsonNode?>> GetObjectPropertiesViaDocument(JsonObject obj)
263var result = new List<KeyValuePair<string, JsonNode?>>();
268var property = new KeyValuePair<string, JsonNode?>(prop.Name, ParseJsonNode(prop.Value.GetRawText()));
282internal static T? Get<T>(this JsonNode? token, string? key)
283where T : JsonNode
290JsonNode? res = GetPropertyCaseInsensitive(obj, key);
294internal static IReadOnlyDictionary<string, string> ToStringDictionary(this JsonNode token, StringComparer? comparer = null, string? propertyName = null)
315internal static IReadOnlyDictionary<string, JsonNode> ToJsonNodeDictionary(this JsonNode token, StringComparer? comparer = null, string? propertyName = null)
317Dictionary<string, JsonNode> result = new(comparer ?? StringComparer.Ordinal);
334internal static IReadOnlyDictionary<string, string> ToJsonNodeStringDictionary(this JsonNode token, StringComparer? comparer = null, string? propertyName = null)
349internal static TemplateParameterPrecedence ToTemplateParameterPrecedence(this JsonNode jObject, string? key)
351if (!jObject.TryGetValue(key, out JsonNode? checkToken))
364internal static IReadOnlyList<string> ArrayAsStrings(this JsonNode? token, string? propertyName = null)
378foreach (JsonNode? item in arr)
389internal static IReadOnlyList<Guid> ArrayAsGuids(this JsonNode? token, string? propertyName = null)
403foreach (JsonNode? item in arr)
417internal static IEnumerable<T> Items<T>(this JsonNode? token, string? propertyName = null)
418where T : JsonNode
430foreach (JsonNode? item in arr)
444return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
453return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
463internal static IReadOnlyList<string> JTokenStringOrArrayToCollection(this JsonNode? token, IReadOnlyList<string> defaultSet)
503internal static bool TryGetValueCaseInsensitive(this JsonObject obj, string key, out JsonNode? result)
513internal static JsonNode? GetPropertyCaseInsensitive(JsonObject obj, string key)
518if (obj.TryGetPropertyValue(key, out JsonNode? result))
546private static JsonNode? GetPropertyCaseInsensitiveViaDocument(JsonObject obj, string key)
551JsonNode? result = null;
552JsonNode? caseInsensitiveResult = null;
576return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
583internal static JsonNode? ParseJsonNode(string json)
585return JsonNode.Parse(json, null, DocOptions);
599return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
608return (JsonObject?)JsonNode.Parse(source.ToJsonString(), null, DocOptions)
624&& target.TryGetPropertyValue(property.Key, out JsonNode? targetNode)
635foreach (var item in sourceArr)
637targetArr.Add(item != null ? JsonNode.Parse(item.ToJsonString()) : null);
644? JsonNode.Parse(property.Value.ToJsonString())
Microsoft.TemplateSearch.Common (76)
parent\Shared\JExtensions.cs (57)
27internal static string? ToString(this JsonNode? token, string? key)
49JsonNode? element = GetPropertyCaseInsensitive(obj, key);
63internal static bool TryGetValue(this JsonNode? token, string? key, out JsonNode? result)
88internal static bool TryParseBool(this JsonNode token, out bool result)
109internal static bool ToBool(this JsonNode? token, string? key = null, bool defaultValue = false)
111if (!token.TryGetValue(key, out JsonNode? checkToken))
124internal static bool TryParseInt(this JsonNode token, out int result)
144internal static int ToInt32(this JsonNode? token, string? key = null, int defaultValue = 0)
161JsonNode? element = GetPropertyCaseInsensitive(obj, key);
170internal static T ToEnum<T>(this JsonNode token, string? key = null, T defaultValue = default, bool ignoreCase = false)
182internal static Guid ToGuid(this JsonNode token, string? key = null, Guid defaultValue = default)
200JsonNode? token = jObject.Get<JsonNode>(propertyName);
208internal static IEnumerable<KeyValuePair<string, JsonNode?>> PropertiesOf(this JsonNode? token, string? key = null)
217JsonNode? element = GetPropertyCaseInsensitive(obj, key);
236private static IReadOnlyList<KeyValuePair<string, JsonNode?>> GetObjectProperties(JsonObject obj)
256/// when the internal dictionary has not yet been initialized, so <see cref="JsonNode.ToJsonString"/> is
260private static List<KeyValuePair<string, JsonNode?>> GetObjectPropertiesViaDocument(JsonObject obj)
263var result = new List<KeyValuePair<string, JsonNode?>>();
268var property = new KeyValuePair<string, JsonNode?>(prop.Name, ParseJsonNode(prop.Value.GetRawText()));
282internal static T? Get<T>(this JsonNode? token, string? key)
283where T : JsonNode
290JsonNode? res = GetPropertyCaseInsensitive(obj, key);
294internal static IReadOnlyDictionary<string, string> ToStringDictionary(this JsonNode token, StringComparer? comparer = null, string? propertyName = null)
315internal static IReadOnlyDictionary<string, JsonNode> ToJsonNodeDictionary(this JsonNode token, StringComparer? comparer = null, string? propertyName = null)
317Dictionary<string, JsonNode> result = new(comparer ?? StringComparer.Ordinal);
334internal static IReadOnlyDictionary<string, string> ToJsonNodeStringDictionary(this JsonNode token, StringComparer? comparer = null, string? propertyName = null)
349internal static TemplateParameterPrecedence ToTemplateParameterPrecedence(this JsonNode jObject, string? key)
351if (!jObject.TryGetValue(key, out JsonNode? checkToken))
364internal static IReadOnlyList<string> ArrayAsStrings(this JsonNode? token, string? propertyName = null)
378foreach (JsonNode? item in arr)
389internal static IReadOnlyList<Guid> ArrayAsGuids(this JsonNode? token, string? propertyName = null)
403foreach (JsonNode? item in arr)
417internal static IEnumerable<T> Items<T>(this JsonNode? token, string? propertyName = null)
418where T : JsonNode
430foreach (JsonNode? item in arr)
444return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
453return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
463internal static IReadOnlyList<string> JTokenStringOrArrayToCollection(this JsonNode? token, IReadOnlyList<string> defaultSet)
503internal static bool TryGetValueCaseInsensitive(this JsonObject obj, string key, out JsonNode? result)
513internal static JsonNode? GetPropertyCaseInsensitive(JsonObject obj, string key)
518if (obj.TryGetPropertyValue(key, out JsonNode? result))
546private static JsonNode? GetPropertyCaseInsensitiveViaDocument(JsonObject obj, string key)
551JsonNode? result = null;
552JsonNode? caseInsensitiveResult = null;
576return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
583internal static JsonNode? ParseJsonNode(string json)
585return JsonNode.Parse(json, null, DocOptions);
599return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
608return (JsonObject?)JsonNode.Parse(source.ToJsonString(), null, DocOptions)
624&& target.TryGetPropertyValue(property.Key, out JsonNode? targetNode)
635foreach (var item in sourceArr)
637targetArr.Add(item != null ? JsonNode.Parse(item.ToJsonString()) : null);
644? JsonNode.Parse(property.Value.ToJsonString())
MSBuild (3)
sdk-tasks (13)
Shared.Tests (20)
System.Text.Json (475)
System\Text\Json\Nodes\JsonArray.cs (31)
24private List<JsonNode?>? _list;
39public JsonArray(JsonNodeOptions options, params JsonNode?[] items) : base(options)
49public JsonArray(JsonNodeOptions options, params ReadOnlySpan<JsonNode?> items) : base(options)
58public JsonArray(params JsonNode?[] items) : base()
67public JsonArray(params ReadOnlySpan<JsonNode?> items) : base()
74internal override JsonNode DeepCloneCore()
76GetUnderlyingRepresentation(out List<JsonNode?>? list, out JsonElement? jsonElement);
87_list = new List<JsonNode?>(list.Count)
98internal override bool DeepEqualsCore(JsonNode node)
108List<JsonNode?> currentList = List;
109List<JsonNode?> otherList = array.List;
131internal int GetElementIndex(JsonNode? node)
137/// Returns an enumerable that wraps calls to <see cref="JsonNode.GetValue{T}"/>.
143foreach (JsonNode? item in List)
149private void InitializeFromArray(JsonNode?[] items)
151var list = new List<JsonNode?>(items);
161private void InitializeFromSpan(ReadOnlySpan<JsonNode?> items)
163List<JsonNode?> list = new(items.Length);
220JsonNode? nodeToAdd = ConvertFromValue(value, Options);
227private List<JsonNode?> List => _list ?? InitializeList();
229private protected override JsonNode? GetItem(int index)
234private protected override void SetItem(int index, JsonNode? value)
241internal override unsafe void GetPath(ref ValueStringBuilder path, JsonNode? child)
268GetUnderlyingRepresentation(out List<JsonNode?>? list, out JsonElement? jsonElement);
278foreach (JsonNode? element in List)
294private List<JsonNode?> InitializeList()
296GetUnderlyingRepresentation(out List<JsonNode?>? list, out JsonElement? jsonElement);
305list = new List<JsonNode?>(jElement.GetArrayLength());
309JsonNode? node = JsonNodeConverter.Create(element, Options);
332private void GetUnderlyingRepresentation(out List<JsonNode?>? list, out JsonElement? jsonElement)
376public JsonNode? Value;
System\Text\Json\Nodes\JsonObject.cs (34)
36public JsonObject(IEnumerable<KeyValuePair<string, JsonNode?>> properties, JsonNodeOptions? options = null) : this(options)
38int capacity = properties is ICollection<KeyValuePair<string, JsonNode?>> propertiesCollection ? propertiesCollection.Count : 0;
39OrderedDictionary<string, JsonNode?> dictionary = CreateDictionary(options, capacity);
41foreach (KeyValuePair<string, JsonNode?> node in properties)
78private OrderedDictionary<string, JsonNode?> Dictionary => _dictionary ?? InitializeDictionary();
80private protected override JsonNode? GetItem(int index) => GetAt(index).Value;
81private protected override void SetItem(int index, JsonNode? value) => SetAt(index, value);
83internal override JsonNode DeepCloneCore()
85GetUnderlyingRepresentation(out OrderedDictionary<string, JsonNode?>? dictionary, out JsonElement? jsonElement);
99foreach (KeyValuePair<string, JsonNode?> item in dictionary)
107internal string GetPropertyName(JsonNode? node)
109KeyValuePair<string, JsonNode?>? item = FindValue(node);
124public bool TryGetPropertyValue(string propertyName, out JsonNode? jsonNode) => TryGetPropertyValue(propertyName, out jsonNode, out _);
141public bool TryGetPropertyValue(string propertyName, out JsonNode? jsonNode, out int index)
153GetUnderlyingRepresentation(out OrderedDictionary<string, JsonNode?>? dictionary, out JsonElement? jsonElement);
175GetUnderlyingRepresentation(out OrderedDictionary<string, JsonNode?>? dictionary, out JsonElement? jsonElement);
187foreach (KeyValuePair<string, JsonNode?> entry in Dictionary)
205internal override bool DeepEqualsCore(JsonNode node)
215OrderedDictionary<string, JsonNode?> currentDict = Dictionary;
216OrderedDictionary<string, JsonNode?> otherDict = jsonObject.Dictionary;
223foreach (KeyValuePair<string, JsonNode?> item in currentDict)
225if (!otherDict.TryGetValue(item.Key, out JsonNode? jsonNode) || !DeepEquals(item.Value, jsonNode))
238internal JsonNode? GetItem(string propertyName)
242if (TryGetPropertyValue(propertyName, out JsonNode? value))
251internal override void GetPath(ref ValueStringBuilder path, JsonNode? child)
272internal void SetItem(string propertyName, JsonNode? value)
276OrderedDictionary<string, JsonNode?> dict = Dictionary;
281JsonNode? replacedValue = dict.GetAt(index).Value;
295private void DetachParent(JsonNode? item)
302private KeyValuePair<string, JsonNode?>? FindValue(JsonNode? value)
304foreach (KeyValuePair<string, JsonNode?> item in Dictionary)
337foreach (KeyValuePair<string, JsonNode?> item in _node)
352public JsonNode? Value;
System\Text\Json\Nodes\JsonObject.IDictionary.cs (31)
13private OrderedDictionary<string, JsonNode?>? _dictionary;
26public void Add(string propertyName, JsonNode? value)
43public bool TryAdd(string propertyName, JsonNode? value) => TryAdd(propertyName, value, out _);
55public bool TryAdd(string propertyName, JsonNode? value, out int index)
81public void Add(KeyValuePair<string, JsonNode?> property) => Add(property.Key, property.Value);
88OrderedDictionary<string, JsonNode?>? dictionary = _dictionary;
96foreach (JsonNode? node in dictionary.Values)
140bool success = Dictionary.Remove(propertyName, out JsonNode? removedNode);
150/// Determines whether the <see cref="JsonObject"/> contains a specific property name and <see cref="JsonNode"/> reference.
156bool ICollection<KeyValuePair<string, JsonNode?>>.Contains(KeyValuePair<string, JsonNode?> item) =>
157((IDictionary<string, JsonNode?>)Dictionary).Contains(item);
176void ICollection<KeyValuePair<string, JsonNode?>>.CopyTo(KeyValuePair<string, JsonNode?>[] array, int index) =>
177((IDictionary<string, JsonNode?>)Dictionary).CopyTo(array, index);
185public IEnumerator<KeyValuePair<string, JsonNode?>> GetEnumerator() => Dictionary.GetEnumerator();
196bool ICollection<KeyValuePair<string, JsonNode?>>.Remove(KeyValuePair<string, JsonNode?> item) => Remove(item.Key);
201ICollection<string> IDictionary<string, JsonNode?>.Keys => Dictionary.Keys;
206ICollection<JsonNode?> IDictionary<string, JsonNode?>.Values => Dictionary.Values;
222bool IDictionary<string, JsonNode?>.TryGetValue(string propertyName, out JsonNode? jsonNode)
232bool ICollection<KeyValuePair<string, JsonNode?>>.IsReadOnly => false;
242private OrderedDictionary<string, JsonNode?> InitializeDictionary()
244GetUnderlyingRepresentation(out OrderedDictionary<string, JsonNode?>? dictionary, out JsonElement? jsonElement);
248OrderedDictionary<string, JsonNode?> newDictionary = CreateDictionary(Options);
254JsonNode? node = JsonNodeConverter.Create(jElementProperty.Value, Options);
262OrderedDictionary<string, JsonNode?>? exchangedDictionary = Interlocked.CompareExchange(ref _dictionary, newDictionary, null);
280private static OrderedDictionary<string, JsonNode?> CreateDictionary(JsonNodeOptions? options, int capacity = 0)
293private void GetUnderlyingRepresentation(out OrderedDictionary<string, JsonNode?>? dictionary, out JsonElement? jsonElement)
System\Text\Json\Nodes\JsonObject.IList.cs (17)
15public KeyValuePair<string, JsonNode?> GetAt(int index) => Dictionary.GetAt(index);
24public void SetAt(int index, string propertyName, JsonNode? value)
28OrderedDictionary<string, JsonNode?> dictionary = Dictionary;
29KeyValuePair<string, JsonNode?> existing = dictionary.GetAt(index);
40public void SetAt(int index, JsonNode? value)
42OrderedDictionary<string, JsonNode?> dictionary = Dictionary;
43KeyValuePair<string, JsonNode?> existing = dictionary.GetAt(index);
67public void Insert(int index, string propertyName, JsonNode? value)
80KeyValuePair<string, JsonNode?> existing = Dictionary.GetAt(index);
86KeyValuePair<string, JsonNode?> IList<KeyValuePair<string, JsonNode?>>.this[int index]
93int IList<KeyValuePair<string, JsonNode?>>.IndexOf(KeyValuePair<string, JsonNode?> item) => ((IList<KeyValuePair<string, JsonNode?>>)Dictionary).IndexOf(item);
96void IList<KeyValuePair<string, JsonNode?>>.Insert(int index, KeyValuePair<string, JsonNode?> item) => Insert(index, item.Key, item.Value);
99void IList<KeyValuePair<string, JsonNode?>>.RemoveAt(int index) => RemoveAt(index);
System\Text\Json\Serialization\JsonSerializer.Write.Node.cs (19)
15/// Converts the provided value into a <see cref="JsonNode"/>.
18/// <returns>A <see cref="JsonNode"/> representation of the JSON value.</returns>
27public static JsonNode? SerializeToNode<TValue>(TValue value, JsonSerializerOptions? options = null)
34/// Converts the provided value into a <see cref="JsonNode"/>.
36/// <returns>A <see cref="JsonNode"/> representation of the value.</returns>
52public static JsonNode? SerializeToNode(object? value, Type inputType, JsonSerializerOptions? options = null)
60/// Converts the provided value into a <see cref="JsonNode"/>.
63/// <returns>A <see cref="JsonNode"/> representation of the value.</returns>
69public static JsonNode? SerializeToNode<TValue>(TValue value, JsonTypeInfo<TValue> jsonTypeInfo)
78/// Converts the provided value into a <see cref="JsonNode"/>.
80/// <returns>A <see cref="JsonNode"/> representation of the value.</returns>
89public static JsonNode? SerializeToNode(object? value, JsonTypeInfo jsonTypeInfo)
98/// Converts the provided value into a <see cref="JsonNode"/>.
100/// <returns>A <see cref="JsonNode"/> representation of the value.</returns>
115public static JsonNode? SerializeToNode(object? value, Type inputType, JsonSerializerContext context)
124private static JsonNode? WriteNode<TValue>(in TValue value, JsonTypeInfo<TValue> jsonTypeInfo)
134return JsonNode.Parse(output.WrittenSpan, options.GetNodeOptions(), options.GetDocumentOptions());
142private static JsonNode? WriteNodeAsObject(object? value, JsonTypeInfo jsonTypeInfo)
152return JsonNode.Parse(output.WrittenSpan, options.GetNodeOptions(), options.GetDocumentOptions());