7 types derived from JsonNode
System.Text.Json (7)
2732 references to JsonNode
aspire (117)
Aspire.Cli.EndToEnd.Tests (34)
Aspire.Cli.Tests (157)
Mcp\ListResourcesToolTests.cs (13)
397Properties = new Dictionary<string, JsonNode?>
729Properties = new Dictionary<string, JsonNode?>
739Properties = new Dictionary<string, JsonNode?>
767Properties = new Dictionary<string, JsonNode?>
778Properties = new Dictionary<string, JsonNode?>
789Properties = new Dictionary<string, JsonNode?>
818Properties = new Dictionary<string, JsonNode?>
891Properties = new Dictionary<string, JsonNode?>
969Properties = new Dictionary<string, JsonNode?>
980Properties = new Dictionary<string, JsonNode?>
990Properties = new Dictionary<string, JsonNode?>
1000Properties = new Dictionary<string, JsonNode?>
1058Properties = new Dictionary<string, JsonNode?>
Aspire.Dashboard (34)
Aspire.Dashboard.Components.Tests (2)
Aspire.Dashboard.Tests (21)
Aspire.Hosting (94)
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)
268protected override JsonNode? GetSectionState(JsonObject? state, string sectionName, bool includeLegacyState)
283var mergedSection = base.GetSectionState(state, sectionName, includeLegacyState)?.DeepClone();
347var legacySectionData = TryGetNestedPropertyValue(GetLegacyFallbackState(), sectionName);
378private static JsonObject? NormalizeSectionData(JsonNode? sectionData) =>
499JsonNode? legacyValue,
500JsonNode? savedValue,
512JsonNode? baseline,
514JsonNode? value,
522var baselinePropertyExists = baselineObject.TryGetPropertyValue(propertyName, out var baselineProperty);
523var savedPropertyExists = valueObject.TryGetPropertyValue(propertyName, out var valueProperty);
535if (baselineExists == savedExists && JsonNode.DeepEquals(baseline, value))
545private static JsonNode? ApplyChanges(JsonNode? latestValue, JsonNode? originalValue, JsonNode? savedValue)
557var originalPropertyExists = originalObject.TryGetPropertyValue(propertyName, out var originalProperty);
558var savedPropertyExists = savedObject.TryGetPropertyValue(propertyName, out var savedProperty);
559var latestPropertyExists = result.TryGetPropertyValue(propertyName, out var latestProperty);
580return JsonNode.DeepEquals(originalValue, savedValue)
584static (bool Exists, JsonNode? Value) ApplyPropertyChanges(
585JsonNode? latestValue,
587JsonNode? originalValue,
589JsonNode? savedValue,
592if (originalExists == savedExists && JsonNode.DeepEquals(originalValue, savedValue))
645if (!current.TryGetPropertyValue(segments[i], out var nextNode) ||
657private static void SetNestedNodeValue(JsonObject root, string path, JsonNode? value, bool valueExists)
664if (!current.TryGetPropertyValue(segment, out var nextNode) || nextNode is not JsonObject nextObject)
761JsonValue stateValue => JsonNode.Parse(stateValue.GetValue<string>())?.AsObject()
Aspire.Hosting.Azure (24)
AzureProvisioningController.cs (8)
1929var outputs = ParseDeploymentStateJson(resource.Name, "Outputs", section.Data["Outputs"]?.GetValue<string>());
2552json["remainingResources"] = new JsonArray([.. result.RemainingResources.Select(resource => (JsonNode)new JsonObject
2617deployment.TryGetPropertyValue("resourceId", out var resourceIdNode) ? resourceIdNode?.GetValue<string>() : null,
2632var outputs = ParseDeploymentStateJson(resource.Name, "Outputs", section.Data["Outputs"]?.GetValue<string>());
2747private JsonNode? ParseDeploymentStateJson(string resourceName, string propertyName, string? json)
2771private static string? TryGetOutputValue(JsonNode? outputs, string outputName)
2777!outputsObject.TryGetPropertyValue(outputName, out var outputNode) ||
2779!outputObject.TryGetPropertyValue("value", out var valueNode))
Aspire.Hosting.Azure.EntraId.Tests (1)
Aspire.Hosting.Azure.EventHubs (5)
Aspire.Hosting.Azure.Kubernetes (2)
Aspire.Hosting.Azure.Sandboxes (3)
Aspire.Hosting.Azure.ServiceBus (5)
Aspire.Hosting.Azure.Tests (54)
Aspire.Hosting.Azure.WebPubSub (1)
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 (4)
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.Native.Client (4)
Aspire.Hosting.Native.CodeGeneration (2)
Aspire.Hosting.Native.Core.Tests (238)
ApplicationRevisionTests.cs (51)
26var original = context.Read();
27var revision = context.BeginRevision();
28var resource = context.Author.AddResource(revision, "cache");
30var current = context.Read();
37var resourceId = current["resources"]![0]!["resourceId"];
38var logs = Result(context.Observer.Invoke("readResourceLogs",
41var execution = Result(context.Author.Invoke("getApplicationExecution", Arguments(("context", context.Workspace))));
42var invitation = Result(context.Author.Invoke("inviteResourceExecution",
57var command = Result(context.Observer.Invoke("invokeResourceCommand", Arguments(
59var confirmation = Result(context.Integration.Invoke("requestConfirmation", Arguments(
63var commands = Result(context.Integration.Invoke("readResourceCommands", Arguments(("context", context.Writer))));
64var confirmations = Result(context.Observer.Invoke("readConfirmations", Arguments(("context", context.Reader))));
66var revision = context.BeginRevision();
92var original = context.Read();
93var abandoned = context.BeginRevision();
97var revision = context.BeginRevision();
110var original = context.Read();
111var revision = context.BeginRevision();
112var a = context.Author.AddResource(revision, "a");
113var b = context.Author.AddResource(revision, "b");
129var revision = context.BeginRevision();
156var revision = context.BeginRevision();
157var replacement = Result(context.Author.Invoke("addResource",
163var execution = Result(context.Author.Invoke("getApplicationExecution", Arguments(("context", context.Workspace))));
175var revision = context.BeginRevision();
176var resource = context.Author.AddResource(revision, "cache");
179var change = Result(await waiting);
188var next = context.BeginRevision();
189var nextResource = context.Author.AddResource(next, "cache");
202var revision = context.BeginRevision();
203var cache = context.Author.AddResource(revision, "cache");
204var dependency = context.Author.AddResource(revision, "database");
207var configuration = Result(context.Integration.Invoke("readResourceConfiguration", Arguments(("context", context.Writer))));
208var database = context.Read()["resources"]![1]!;
219var revision = foreign.BeginRevision();
222var invitation = Result(context.Author.Invoke("inviteApplicationWorkspace", Arguments(("context", context.Workspace))));
223var root = Result(context.Integration.Call("getApplicationServer", null));
237var revision = context.BeginRevision();
238var cache = context.Author.AddResource(revision, "cache");
239var dependent = context.Author.AddResource(revision, "tunnel");
242var execution = Result(context.Author.Invoke("getApplicationExecution", Arguments(("context", context.Workspace))));
243var writer = Result(context.Integration.Invoke("joinResourceExecution", Arguments(
262var configuration = Result(context.Integration.Invoke("readResourceConfiguration", Arguments(("context", writer))));
265var dependencies = Result(context.Integration.Invoke("readResourceDependencies", Arguments(("context", writer))));
278var revision = context.BeginRevision();
279var cache = context.Author.AddResource(revision, "cache");
342var revision = context.BeginRevision();
359var revision = context.BeginRevision();
366private static JsonObject RestartArguments(JsonNode writer, long revision) =>
381private static Task<JsonObject> Commit(WorkspaceRpcTestContext context, JsonNode revision) =>
384private static void SetConfiguration(RpcTestClient author, JsonNode resource, string value) =>
NativeComposeCSharpTests.cs (26)
27Assert.True(JsonNode.DeepEquals(first.Compose, second.Compose));
28Assert.True(JsonNode.DeepEquals(first.Inputs, second.Inputs));
31var build = first.Compose["services"]!["web"]!["build"]!;
70var cache = context.Model["resources"]!.AsArray().Single(resource => resource!["name"]!.GetValue<string>() == "cache")!;
71var web = context.Model["resources"]!.AsArray().Single(resource => resource!["name"]!.GetValue<string>() == "web")!;
72var target = context.Model["resources"]!.AsArray().Single(resource => resource!["name"]!.GetValue<string>() == "compose")!;
91var options = JsonNode.Parse(web["configuration"]!["publish.dockerCompose"]!.GetValue<string>())!;
103var other = target.DeepClone();
106var isolated = cache.DeepClone();
135["environment"] = new JsonObject(environment.Select(pair => KeyValuePair.Create(pair.Key, (JsonNode?)JsonValue.Create(pair.Value))))
150var typescript = JsonNode.Parse(await stdout)!.AsObject();
151Assert.True(JsonNode.DeepEquals(plan.Compose, typescript["compose"]), "C# and TypeScript Compose documents differ.");
152Assert.True(JsonNode.DeepEquals(plan.Inputs, typescript["inputs"]), "C# and TypeScript input contracts differ.");
153Assert.True(JsonNode.DeepEquals(JsonSerializer.SerializeToNode(plan.Services, new JsonSerializerOptions(JsonSerializerDefaults.Web)
206var document = JsonNode.Parse(await File.ReadAllTextAsync(Path.Combine(context.OutputPath, "compose.yaml")))!;
248var state = JsonNode.Parse(await File.ReadAllTextAsync(Path.Combine(context.OutputPath, "deployment-state.json")))!;
374var model = JsonNode.Parse(await composition.ExportPublishModelAsync())!;
417var resource = context.Model["resources"]!.AsArray().Single(resource => resource!["name"]!.GetValue<string>() == "web")!;
438var environment = resources.Single(resource => resource!["name"]!.GetValue<string>() == "compose")!.DeepClone();
441var cache = resources.Single(resource => resource!["name"]!.GetValue<string>() == "cache")!;
465var environment = context.Model["resources"]!.AsArray().Single(resource => resource!["name"]!.GetValue<string>() == "compose")!;
531var model = JsonNode.Parse(await composition.ExportPublishModelAsync())!.AsObject();
NativeRpcTests.cs (33)
19var contract = Result(client.Call("getCapabilities", null));
39var session = client.CreateSession();
40var composition = client.StartGeneration(session);
41var web = client.AddResource(composition, "web");
42var cache = client.AddResource(composition, "cache");
46var snapshot = Result(client.Invoke("seal", Arguments(("context", composition))));
68var session = client.CreateSession();
71var composition = client.StartGeneration(session);
72var resource = client.AddResource(composition, "cache");
78var replacement = client.StartGeneration(session);
86var retiredSession = client.CreateSession();
87var liveSession = client.CreateSession();
88var retired = client.StartGeneration(retiredSession);
89var live = client.StartGeneration(liveSession);
90var liveResources = new JsonNode[128];
104var replacement = client.StartGeneration(retiredSession);
105var added = client.AddResource(replacement, "replacement");
115var composition = first.StartGeneration(first.CreateSession());
116var resource = first.AddResource(composition, "cache");
118var forged = resource.DeepClone();
121var retagged = resource.DeepClone();
132var session = first.CreateSession();
133var composition = first.StartGeneration(session);
134var value = Result(first.Invoke("addSecretParameter", Arguments(("context", composition),
136var resource = second.AddResource(second.StartGeneration(second.CreateSession()), "consumer");
149var first = client.CreateSession();
150var second = client.CreateSession();
151var composition = client.StartGeneration(first);
160var composition = client.StartGeneration(client.CreateSession());
181Assert.Equal(classification, Error(JsonNode.Parse(response!)!.AsObject()));
201Assert.Equal("REQUEST_TOO_LARGE", Error(JsonNode.Parse(connection.Process(new byte[Aspire.Hosting.Native.Server.NativeServerOptions.DefaultMaximumRequestBytes + 1])!)!.AsObject()));
203var composition = client.StartGeneration(client.CreateSession());
218var composition = client.StartGeneration(client.CreateSession());
NativeSocketIsolationTests.cs (9)
34var error = (await unauthenticated.CallAsync("getApplicationServer", null, timeout.Token))["error"]!;
136var server = Result(await failing.CallAsync("getApplicationServer", null, timeout.Token));
137var authorServer = Result(context.Author.Call("getApplicationServer", null));
138var session = Result(context.Author.Invoke("openApplication", Arguments(("context", authorServer))));
139var composition = context.Author.StartGeneration(session);
140var resource = context.Author.AddResource(composition, "failure");
141var execution = Result(context.Author.Invoke("createExecution", Arguments(("context", composition))));
142var invitation = Result(context.Author.Invoke("inviteResourceExecution",
144var writer = Result(await failing.CallAsync("invokeCapability", new JsonArray("Aspire.Hosting.Native.Api/joinResourceExecution",
RuntimeRpcTests.cs (20)
23var id = context.Read()["resources"]![0]!["resourceId"];
24var logs = Result(context.Observer.Invoke("readResourceLogs", Arguments(("context", context.Reader),
37var initial = context.Read();
43var updated = Result(await wait.WaitAsync(TimeSpan.FromSeconds(10)));
45var resource = Assert.Single(updated["resources"]!.AsArray())!;
58var root = Result(context.Observer.Call("getApplicationServer", null));
59var invite = Result(context.Author.Invoke("inviteApplicationObserver", Arguments(("context", context.Execution))));
66var stale = Result(context.Author.Invoke("inviteApplicationObserver", Arguments(("context", context.Execution))));
83var id = context.Read()["resources"]![0]!["resourceId"];
84var logs = Result(context.Observer.Invoke("readResourceLogs", Arguments(("context", context.Reader),
90var suffix = Result(context.Observer.Invoke("readResourceLogs", Arguments(("context", context.Reader),
104var command = Result(context.Observer.Invoke("invokeResourceCommand", Arguments(("context", context.Reader),
108var pending = Result(context.Integration.Invoke("readResourceCommands", Arguments(("context", context.Writer))))["commands"]![0]!;
112var result = Result(await completion.WaitAsync(TimeSpan.FromSeconds(10)));
115var confirmation = Result(context.Integration.Invoke("requestConfirmation", Arguments(("context", context.Writer),
118var prompt = Assert.Single(Result(context.Observer.Invoke("readConfirmations", Arguments(("context", context.Reader))))["requests"]!.AsArray())!;
135var command = Result(context.Observer.Invoke("invokeResourceCommand", Arguments(("context", context.Reader),
140var resource = context.Read()["resources"]![0]!;
151var prompt = Result(context.Integration.Invoke("requestConfirmation", Arguments(("context", context.Writer),
170("context", context.Writer), ("observation", JsonNode.Parse(observation))))));
Aspire.Hosting.Native.Server (87)
Rpc\NativeProviderRegistry.cs (19)
22Task<JsonNode?> InvokeAsync(NativeRpcConnection caller, string capability, JsonObject arguments);
23Task<JsonNode?> InvokeCoreAsync(NativeRpcConnection provider, string capability, JsonObject arguments);
24Task<JsonNode?> InvokeCallbackAsync(NativeRpcConnection provider, string callback, JsonObject arguments);
186.Select(pair => (JsonNode?)pair.Value.Capabilities[pair.Key].Metadata.DeepClone()).ToArray())
191public async Task<JsonNode?> InvokeAsync(NativeRpcConnection caller, string capability, JsonObject arguments)
236var result = await registration.Peer.RequestAsync("handleExternalCapability",
240var translated = ToCaller(registration, caller, result, metadata.ReturnType, out var callbackOwner);
281public async Task<JsonNode?> InvokeCoreAsync(NativeRpcConnection provider, string capability, JsonObject arguments)
294JsonNode? Translate(JsonNode? value)
334var result = await origin.InvokeCoreAsync(capability, translated, provider).ConfigureAwait(false);
337JsonNode? DelegateResult(JsonNode? value)
355public async Task<JsonNode?> InvokeCallbackAsync(NativeRpcConnection provider, string callbackId, JsonObject arguments)
376var result = await callback.Owner.RequestAsync("invokeCallback",
381private JsonNode? ToProvider(Registration registration, NativeRpcConnection caller, JsonNode? value, NativeProviderType type,
409private JsonNode? ToCaller(Registration registration, NativeRpcConnection caller, JsonNode? value, NativeProviderType type,
Rpc\NativeRpcConnection.cs (14)
90!JsonNode.DeepEquals(next.Lifetime, previous.Lifetime))
163internal Task<JsonNode?> RequestAsync(string method, JsonArray arguments) =>
199var response = await (callbackConnection._peer ?? throw RpcFault.NotSupported("Bidirectional RPC is not configured."))
205if (response is not null && !JsonNode.DeepEquals(arguments, response))
211internal async Task<JsonNode?> InvokeCoreAsync(string capability, JsonObject arguments, NativeRpcConnection callbackConnection)
213Task<JsonNode?> invocation;
323JsonNode? id;
326Task<JsonNode?> invocation;
363var result = await invocation.WaitAsync(lifetime).ConfigureAwait(false);
435private async Task<JsonNode?> InvokeAsync(string method, JsonNode? parameters)
511private static byte[] EncodeError(JsonNode? id, int code, string classification, string message) => Encode(new NativeRpcResponse
517private static byte[] EncodeFailure(JsonNode? id, string method, int code, string classification, string message)
544return JsonNode.Parse(stream) as JsonObject
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.Radius (1)
Aspire.Hosting.Redis.Tests (17)
Aspire.Hosting.RemoteHost (87)
Ats\AtsCallbackProxyFactory.cs (14)
141var addMethod = jsonObjectType.GetMethod("Add", [typeof(string), typeof(JsonNode)]);
180private JsonNode? MarshalArg(object? value, Type declaredType)
248_invoker.InvokeAsync<JsonNode?>(callbackId, args, cancellationToken).GetAwaiter().GetResult();
254var result = _invoker.InvokeAsync<JsonNode?>(callbackId, args, cancellationToken).GetAwaiter().GetResult();
261var result = _invoker.InvokeAsync<JsonNode?>(callbackId, args, cancellationToken).GetAwaiter().GetResult();
268await _invoker.InvokeAsync<JsonNode?>(callbackId, args, cancellationToken).ConfigureAwait(false);
274var result = await _invoker.InvokeAsync<JsonNode?>(callbackId, args, cancellationToken).ConfigureAwait(false);
281var result = await _invoker.InvokeAsync<JsonNode?>(callbackId, args, cancellationToken).ConfigureAwait(false);
285private T? UnmarshalResult<T>(JsonNode? result, string callbackId)
380private void ApplyDtoWriteback(JsonNode? result, object?[] originalArgs, Type[] argTypes)
Ats\CapabilityDispatcher.cs (19)
21internal delegate Task<JsonNode?> CapabilityHandler(
187if (args == null || !args.TryGetPropertyValue("context", out var contextNode))
234if (args == null || !args.TryGetPropertyValue("context", out var contextNode))
250if (!args.TryGetPropertyValue("value", out var valueNode))
281return Task.FromResult<JsonNode?>(new JsonObject
312if (args == null || !args.TryGetPropertyValue("context", out var contextNode))
335if (args.TryGetPropertyValue(paramName, out var argNode))
432if (args != null && args.TryGetPropertyValue(paramName, out var argNode))
545public async Task<JsonNode?> InvokeAsync(
650public JsonNode? Invoke(string capabilityId, JsonObject? args)
780JsonNode? argNode,
823JsonNode? argNode,
965private static bool IsRejectedEnumString(JsonNode? node, Type unionMemberType)
973private static string DescribeJsonNode(JsonNode? node)
1057if (!args.TryGetPropertyValue(name, out var node) || node is not JsonValue value)
1071if (args.TryGetPropertyValue(name, out var node) && node is JsonValue value)
1083if (args.TryGetPropertyValue(name, out var node) && node is JsonValue value)
1099if (!args.TryGetPropertyValue(name, out var node))
1126if (args.TryGetPropertyValue(name, out var node) && node is JsonObject obj)
Aspire.Hosting.RemoteHost.Tests (163)
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)
ExternalCapabilityRegistryTests.cs (25)
30return Task.FromResult<JsonNode?>(null);
60var response = new TaskCompletionSource<JsonNode?>(TaskCreationOptions.RunContinuationsAsynchronously);
103var payload = JsonNode.Parse(CreateCapabilities("test.external/value").GetRawText())!.AsObject();
109(_, _) => Task.FromResult<JsonNode?>(JsonValue.Create("configured")));
148var payload = JsonNode.Parse(CreateCapabilities("test.external/valid", "test.external/invalid").GetRawText())!.AsObject();
189return Task.FromResult<JsonNode?>(null);
194return Task.FromResult<JsonNode?>(JsonValue.Create($"deferred-{args!["p0"]!.GetValue<string>()}"));
201var result = await registry.InvokeGuestCallbackAsync(integration.ServerRpc, relayId,
219var response = new TaskCompletionSource<JsonNode?>(TaskCreationOptions.RunContinuationsAsynchronously);
246var payload = JsonNode.Parse(CreateCapabilities("test.external/cancel").GetRawText())!.AsObject();
252var response = new TaskCompletionSource<JsonNode?>(TaskCreationOptions.RunContinuationsAsynchronously);
300return Task.FromResult<JsonNode?>(null);
303var response = new TaskCompletionSource<JsonNode?>(TaskCreationOptions.RunContinuationsAsynchronously);
322var result = await invocation.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
357return Task.FromResult<JsonNode?>(null);
360var response = new TaskCompletionSource<JsonNode?>(TaskCreationOptions.RunContinuationsAsynchronously);
496(_, _) => Task.FromResult<JsonNode?>(JsonValue.Create("original")));
498(_, _) => Task.FromResult<JsonNode?>(JsonValue.Create("other")));
500(_, _) => Task.FromResult<JsonNode?>(JsonValue.Create("replacement")));
554var payload = JsonNode.Parse(CreateCapabilities("test.external/value").GetRawText())!.AsObject();
604(_, _) => Task.FromResult<JsonNode?>(JsonValue.Create("first-replacement")));
606(_, _) => Task.FromResult<JsonNode?>(JsonValue.Create("second-replacement")));
628var response = new TaskCompletionSource<JsonNode?>(TaskCreationOptions.RunContinuationsAsynchronously);
660var firstResponse = new TaskCompletionSource<JsonNode?>(TaskCreationOptions.RunContinuationsAsynchronously);
661var secondResponse = new TaskCompletionSource<JsonNode?>(TaskCreationOptions.RunContinuationsAsynchronously);
TestServices\IntegrationHostTestConnection.cs (4)
22public IntegrationHostTestConnection(JsonElement capabilities, Func<string, JsonObject?, Task<JsonNode?>> handleCapability)
27public IntegrationHostTestConnection(JsonElement capabilities, Func<string, JsonObject?, CancellationToken, Task<JsonNode?>> invokeCallback)
39Func<string, JsonObject?, Task<JsonNode?>>? handleCapability,
40Func<string, JsonObject?, CancellationToken, Task<JsonNode?>>? invokeCallback)
Aspire.Hosting.Seq.Tests (3)
Aspire.Hosting.SqlServer.Tests (3)
Aspire.Hosting.Tests (73)
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.Managed.Tests (1)
Aspire.TypeSystem (1)
ConfigurationSchemaGenerator (15)
ConfigurationSchemaGenerator.Tests (4)
dotnet-aot (4)
dotnet-user-jwts (1)
GenerateTemplateManifest (1)
Infrastructure.Tests (188)
WorkflowScripts\AutoSecWorkflowTests.cs (167)
26var result = await RunHarnessAsync(new JsonObject
57var alert = Assert.Single(result["alerts"]!.AsArray())!;
73var result = await RunHarnessAsync(new JsonObject { ["mode"] = "collect-alerts", ["failure"] = phase });
106var result = await RunHarnessAsync(request);
122var file = request["changedFiles"]![1]![0]!;
141var result = await RunHarnessAsync(request);
144var pr = Assert.Single(result["output"]!.AsArray())!;
178var result = await RunHarnessAsync(request);
188var result = await RunHarnessAsync(CreateApprovalScenario());
190var decision = Assert.Single(result["value"]!.AsArray());
194var review = Assert.Single(result["reviews"]!.AsArray());
207var result = await RunHarnessAsync(scenario);
238var result = await RunHarnessAsync(scenario);
266var result = await RunHarnessAsync(scenario);
286var result = await RunHarnessAsync(scenario);
315var result = await RunHarnessAsync(scenario);
339var result = await RunHarnessAsync(scenario);
351var decision = Assert.Single(result["value"]!.AsArray());
410var result = await RunHarnessAsync(scenario);
412var decision = Assert.Single(result["value"]!.AsArray());
436var unchanged = await RunHarnessAsync(scenario);
441var result = await RunHarnessAsync(scenario);
443var decision = Assert.Single(result["value"]!.AsArray());
705var result = await RunHarnessAsync(scenario);
707var decision = Assert.Single(result["value"]!.AsArray());
719var result = await RunHarnessAsync(new JsonObject
752var result = await RunHarnessAsync(new JsonObject
773var result = await RunHarnessAsync(new JsonObject
830var result = await RunHarnessAsync(new JsonObject
929var result = await RunHarnessAsync(request);
975var result = await RunHarnessAsync(new JsonObject
1011var result = await RunHarnessAsync(new JsonObject
1053var result = await RunHarnessAsync(request);
1127var result = await RunHarnessAsync(new JsonObject
1154var result = await RunHarnessAsync(new JsonObject
1171var result = await RunHarnessAsync(new JsonObject
1195var result = await RunHarnessAsync(new JsonObject
1290var result = await RunHarnessAsync(new JsonObject
1335var result = await RunHarnessAsync(new JsonObject
1349var result = await RunHarnessAsync(new JsonObject
1379var result = await RunHarnessAsync(new JsonObject
1410var result = await RunHarnessAsync(new JsonObject
1448var result = await RunHarnessAsync(new JsonObject
1475var result = await RunHarnessAsync(new JsonObject
1499var result = await RunHarnessAsync(new JsonObject
1538var result = await RunHarnessAsync(new JsonObject
1601var result = await RunHarnessAsync(new JsonObject
1672var text = JsonNode.Parse(files[path]!.GetValue<string>())!.ToJsonString(new JsonSerializerOptions { WriteIndented = true }).ReplaceLineEndings("\n") + "\n";
1678var head = JsonNode.Parse(heads["extension/package-lock.json"]!.GetValue<string>())!;
1687var result = await RunHarnessAsync(new JsonObject
1729var result = await RunHarnessAsync(new JsonObject
1748var result = await RunHarnessAsync(new JsonObject
1758Assert.Equal([output], result["outputs"]!.AsArray().Select(v => JsonNode.Parse(v!.GetValue<string>())!.ToJsonString()));
1767var result = await RunHarnessAsync(new JsonObject
1795var outputs = result["outputs"]!.AsArray().Select(line => JsonNode.Parse(line!.GetValue<string>())!).ToArray();
1810var result = await RunHarnessAsync(new JsonObject
1845var result = await RunHarnessAsync(new JsonObject
1892var baseline = JsonNode.Parse(baseText)!;
1896var head = JsonNode.Parse(baseText.Replace("4.17.20", "4.17.21", StringComparison.Ordinal).Replace("22.0.0", "22.1.0", StringComparison.Ordinal))!;
1897var package = head["packages"]!["node_modules/lodash"]!;
1950var result = await RunHarnessAsync(new JsonObject
2012baseline["packages"] = JsonNode.Parse(PublicTextBase)!["packages"]!.DeepClone();
2017var result = await RunHarnessAsync(new JsonObject
2054var baseline = JsonNode.Parse(PublicTextBase)!;
2083var head = baseline.DeepClone();
2111var result = await RunHarnessAsync(new JsonObject
2202var result = await RunHarnessAsync(new JsonObject
2238var baseline = JsonNode.Parse(PublicTextBase)!;
2243var result = await RunHarnessAsync(new JsonObject
2270var baseline = JsonNode.Parse(PublicTextBase)!;
2282var head = baseline.DeepClone();
2307var result = await RunHarnessAsync(new JsonObject
2361var result = await RunHarnessAsync(new JsonObject
2430var result = await RunHarnessAsync(new JsonObject
2473var result = await RunHarnessAsync(new JsonObject
2512var result = await RunHarnessAsync(new JsonObject
2542var result = await RunHarnessAsync(new JsonObject
2578var result = await RunHarnessAsync(new JsonObject
2633var result = await RunHarnessAsync(new JsonObject
2661var result = await RunHarnessAsync(new JsonObject
2681var result = await RunHarnessAsync(new JsonObject
2729var result = await RunHarnessAsync(new JsonObject
2761var result = await RunHarnessAsync(new JsonObject
2806var result = await RunHarnessAsync(new JsonObject
2846var result = await RunHarnessAsync(new JsonObject
2866var result = await RunHarnessAsync(new JsonObject
2901var result = await RunHarnessAsync(new JsonObject
2922var result = await RunHarnessAsync(new JsonObject
2948var result = await RunHarnessAsync(new JsonObject
2978var result = await RunHarnessAsync(new JsonObject
3006var result = await RunHarnessAsync(new JsonObject
3038var result = await RunHarnessAsync(request);
3061var result = await RunHarnessAsync(new JsonObject
3071var output = JsonNode.Parse(Assert.Single(result["outputs"]!.AsArray())!.GetValue<string>());
3072Assert.True(JsonNode.DeepEquals(expected, output));
3093var result = await RunHarnessAsync(new JsonObject
3101var output = JsonNode.Parse(Assert.Single(result["outputs"]!.AsArray())!.GetValue<string>());
3102Assert.True(JsonNode.DeepEquals(expected, output));
3129input[field] = JsonNode.Parse(value);
3130var result = await RunHarnessAsync(new JsonObject
3195var result = await RunHarnessAsync(new JsonObject
3232var result = await RunHarnessAsync(new JsonObject
3269var result = await RunHarnessAsync(new JsonObject
3286var result = await RunHarnessAsync(new JsonObject { ["mode"] = "publication-guard", ["workflow"] = workflow });
3303var result = await RunHarnessAsync(new JsonObject
3320var unguarded = await RunHarnessAsync(new JsonObject { ["mode"] = "private-shell", ["script"] = script });
3328var result = await RunHarnessAsync(new JsonObject { ["mode"] = "publication-guard", ["workflow"] = workflow });
3332var quiet = await RunHarnessAsync(new JsonObject
3348var result = await RunHarnessAsync(new JsonObject { ["mode"] = "publication-guard", ["workflow"] = PublicationGuardFixture });
3369var original = await RunHarnessAsync(new JsonObject { ["mode"] = "private-shell", ["script"] = script });
3376var result = await RunHarnessAsync(new JsonObject { ["mode"] = "publication-guard", ["workflow"] = workflow });
3379var quiet = await RunHarnessAsync(new JsonObject
3402var result = await RunHarnessAsync(new JsonObject { ["mode"] = "publication-guard", ["workflow"] = workflow });
3430var result = await RunHarnessAsync(new JsonObject { ["mode"] = "publication-guard", ["workflow"] = workflow });
3446var result = await RunHarnessAsync(new JsonObject { ["mode"] = "publication-guard", ["workflow"] = workflow });
3473var result = await RunHarnessAsync(new JsonObject { ["mode"] = "publication-guard", ["workflow"] = workflow });
3534var result = await RunHarnessAsync(new JsonObject { ["mode"] = "publication-guard", ["workflow"] = workflow });
3688.Select(step => (JsonNode?)JsonValue.Create(step.Children[new YamlScalarNode("if")].ToString())).ToArray());
3725var result = await RunHarnessAsync(new JsonObject
3748var result = await RunHarnessAsync(new JsonObject
3767var result = await RunHarnessAsync(new JsonObject
3792var result = await RunHarnessAsync(new JsonObject
3829var result = await RunHarnessAsync(new JsonObject
3872var result = await RunHarnessAsync(new JsonObject
3892var result = await RunHarnessAsync(scenario);
3894var decision = Assert.Single(result["value"]!.AsArray());
3915var result = await RunHarnessAsync(scenario);
3917var decision = Assert.Single(result["value"]!.AsArray());
3940var result = await RunHarnessAsync(scenario);
3942var decision = Assert.Single(result["value"]!.AsArray());
3954var result = await RunHarnessAsync(scenario);
3956var decision = Assert.Single(result["value"]!.AsArray());
3985var result = await RunHarnessAsync(scenario);
3987var decision = Assert.Single(result["value"]!.AsArray());
4010var result = await RunHarnessAsync(scenario);
4033var result = await RunHarnessAsync(scenario);
4068var result = await RunHarnessAsync(new JsonObject
4082var result = await RunHarnessAsync(new JsonObject
4129var result = await RunHarnessAsync(new JsonObject
4177var result = await RunHarnessAsync(new JsonObject
4202var result = await RunHarnessAsync(new JsonObject
4216var result = await RunHarnessAsync(new JsonObject
4267var prefixMapped = await RunHarnessAsync(NuGetLookup("Contoso.Build.Engine", config, responses));
4269var exactMapped = await RunHarnessAsync(NuGetLookup("Contoso.Build.Tasks", config, responses.DeepClone().AsObject()));
4308var result = await RunHarnessAsync(new JsonObject
4325var nuget = await RunHarnessAsync(new JsonObject
4338var npm = await RunHarnessAsync(new JsonObject
4362var pip = await RunHarnessAsync(new JsonObject
4388var result = await RunHarnessAsync(CreatePushGateScenario(new JsonObject()));
4393var noPush = await RunHarnessAsync(new JsonObject
4472var result = await RunHarnessAsync(scenario);
4524var result = await RunHarnessAsync(CreatePushGateScenario(pr, item));
4526var failure = Assert.Single(result["failures"]!.AsArray());
4539var result = await RunHarnessAsync(scenario);
4657private static JsonObject Response(JsonNode body) => new() { ["status"] = 200, ["body"] = body };
4720var result = await RunHarnessAsync(new JsonObject
4781private async Task<JsonNode> RunHarnessAsync(JsonObject request)
4804var response = JsonNode.Parse(await File.ReadAllTextAsync(resultPath));
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)
469internal static IReadOnlyList<string> JTokenStringOrArrayToCollection(this JsonNode? token, IReadOnlyList<string> defaultSet)
509internal static bool TryGetValueCaseInsensitive(this JsonObject obj, string key, out JsonNode? result)
519internal static JsonNode? GetPropertyCaseInsensitive(JsonObject obj, string key)
524if (obj.TryGetPropertyValue(key, out JsonNode? result))
552private static JsonNode? GetPropertyCaseInsensitiveViaDocument(JsonObject obj, string key)
557JsonNode? result = null;
558JsonNode? caseInsensitiveResult = null;
582return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
589internal static JsonNode? ParseJsonNode(string json)
591return JsonNode.Parse(json, null, DocOptions);
605return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
614return (JsonObject?)JsonNode.Parse(source.ToJsonString(), null, DocOptions)
630&& target.TryGetPropertyValue(property.Key, out JsonNode? targetNode)
641foreach (var item in sourceArr)
643targetArr.Add(item != null ? JsonNode.Parse(item.ToJsonString()) : null);
650? 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)
469internal static IReadOnlyList<string> JTokenStringOrArrayToCollection(this JsonNode? token, IReadOnlyList<string> defaultSet)
509internal static bool TryGetValueCaseInsensitive(this JsonObject obj, string key, out JsonNode? result)
519internal static JsonNode? GetPropertyCaseInsensitive(JsonObject obj, string key)
524if (obj.TryGetPropertyValue(key, out JsonNode? result))
552private static JsonNode? GetPropertyCaseInsensitiveViaDocument(JsonObject obj, string key)
557JsonNode? result = null;
558JsonNode? caseInsensitiveResult = null;
582return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
589internal static JsonNode? ParseJsonNode(string json)
591return JsonNode.Parse(json, null, DocOptions);
605return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
614return (JsonObject?)JsonNode.Parse(source.ToJsonString(), null, DocOptions)
630&& target.TryGetPropertyValue(property.Key, out JsonNode? targetNode)
641foreach (var item in sourceArr)
643targetArr.Add(item != null ? JsonNode.Parse(item.ToJsonString()) : null);
650? 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)
469internal static IReadOnlyList<string> JTokenStringOrArrayToCollection(this JsonNode? token, IReadOnlyList<string> defaultSet)
509internal static bool TryGetValueCaseInsensitive(this JsonObject obj, string key, out JsonNode? result)
519internal static JsonNode? GetPropertyCaseInsensitive(JsonObject obj, string key)
524if (obj.TryGetPropertyValue(key, out JsonNode? result))
552private static JsonNode? GetPropertyCaseInsensitiveViaDocument(JsonObject obj, string key)
557JsonNode? result = null;
558JsonNode? caseInsensitiveResult = null;
582return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
589internal static JsonNode? ParseJsonNode(string json)
591return JsonNode.Parse(json, null, DocOptions);
605return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
614return (JsonObject?)JsonNode.Parse(source.ToJsonString(), null, DocOptions)
630&& target.TryGetPropertyValue(property.Key, out JsonNode? targetNode)
641foreach (var item in sourceArr)
643targetArr.Add(item != null ? JsonNode.Parse(item.ToJsonString()) : null);
650? 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)
469internal static IReadOnlyList<string> JTokenStringOrArrayToCollection(this JsonNode? token, IReadOnlyList<string> defaultSet)
509internal static bool TryGetValueCaseInsensitive(this JsonObject obj, string key, out JsonNode? result)
519internal static JsonNode? GetPropertyCaseInsensitive(JsonObject obj, string key)
524if (obj.TryGetPropertyValue(key, out JsonNode? result))
552private static JsonNode? GetPropertyCaseInsensitiveViaDocument(JsonObject obj, string key)
557JsonNode? result = null;
558JsonNode? caseInsensitiveResult = null;
582return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
589internal static JsonNode? ParseJsonNode(string json)
591return JsonNode.Parse(json, null, DocOptions);
605return (JsonObject?)JsonNode.Parse(json, null, DocOptions)
614return (JsonObject?)JsonNode.Parse(source.ToJsonString(), null, DocOptions)
630&& target.TryGetPropertyValue(property.Key, out JsonNode? targetNode)
641foreach (var item in sourceArr)
643targetArr.Add(item != null ? JsonNode.Parse(item.ToJsonString()) : null);
650? JsonNode.Parse(property.Value.ToJsonString())
MSBuild (3)
NativeIntegrations.DockerCompose (24)
sdk-tasks (13)
Shared.Tests (20)
System.Text.Json (476)
System\Text\Json\Nodes\JsonArray.cs (32)
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);
213JsonNode? nodeToAdd = ConvertFromValue(value, Options);
220private List<JsonNode?> List => _list ?? InitializeList();
222private protected override JsonNode? GetItem(int index)
227private protected override void SetItem(int index, JsonNode? value)
234internal override unsafe void GetPath(ref ValueStringBuilder path, JsonNode? child)
261GetUnderlyingRepresentation(out List<JsonNode?>? list, out JsonElement? jsonElement);
271foreach (JsonNode? element in List)
287private List<JsonNode?> InitializeList()
289GetUnderlyingRepresentation(out List<JsonNode?>? list, out JsonElement? jsonElement);
298list = new List<JsonNode?>(jElement.GetArrayLength());
302JsonNode? node = JsonNodeConverter.Create(element, Options);
313List<JsonNode?>? exchangedList = Interlocked.CompareExchange(ref _list, list, null);
334private void GetUnderlyingRepresentation(out List<JsonNode?>? list, out JsonElement? jsonElement)
378public 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)
79public void Add(KeyValuePair<string, JsonNode?> property) => Add(property.Key, property.Value);
86OrderedDictionary<string, JsonNode?>? dictionary = _dictionary;
94foreach (JsonNode? node in dictionary.Values)
138bool success = Dictionary.Remove(propertyName, out JsonNode? removedNode);
148/// Determines whether the <see cref="JsonObject"/> contains a specific property name and <see cref="JsonNode"/> reference.
154bool ICollection<KeyValuePair<string, JsonNode?>>.Contains(KeyValuePair<string, JsonNode?> item) =>
155((IDictionary<string, JsonNode?>)Dictionary).Contains(item);
174void ICollection<KeyValuePair<string, JsonNode?>>.CopyTo(KeyValuePair<string, JsonNode?>[] array, int index) =>
175((IDictionary<string, JsonNode?>)Dictionary).CopyTo(array, index);
183public IEnumerator<KeyValuePair<string, JsonNode?>> GetEnumerator() => Dictionary.GetEnumerator();
194bool ICollection<KeyValuePair<string, JsonNode?>>.Remove(KeyValuePair<string, JsonNode?> item) => Remove(item.Key);
199ICollection<string> IDictionary<string, JsonNode?>.Keys => Dictionary.Keys;
204ICollection<JsonNode?> IDictionary<string, JsonNode?>.Values => Dictionary.Values;
220bool IDictionary<string, JsonNode?>.TryGetValue(string propertyName, out JsonNode? jsonNode)
230bool ICollection<KeyValuePair<string, JsonNode?>>.IsReadOnly => false;
240private OrderedDictionary<string, JsonNode?> InitializeDictionary()
242GetUnderlyingRepresentation(out OrderedDictionary<string, JsonNode?>? dictionary, out JsonElement? jsonElement);
246OrderedDictionary<string, JsonNode?> newDictionary = CreateDictionary(Options);
252JsonNode? node = JsonNodeConverter.Create(jElementProperty.Value, Options);
260OrderedDictionary<string, JsonNode?>? exchangedDictionary = Interlocked.CompareExchange(ref _dictionary, newDictionary, null);
278private static OrderedDictionary<string, JsonNode?> CreateDictionary(JsonNodeOptions? options, int capacity = 0)
291private 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());