microsoft/TypeAgent

Public

mirrored fromhttps://github.com/microsoft/TypeAgentAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
d4944c6517c9a96a3c419f827769f518913f1b75

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

dotnet/autoShell/ActionResult.cs

59lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using System.Text.Json;
5using System.Text.Json.Serialization;
6
7namespace autoShell;
8
9/// <summary>
10/// Represents the result of executing an action.
11/// Serialized to JSON and written to stdout as the response to the caller.
12/// </summary>
13internal class ActionResult
14{
15 [JsonPropertyName("id")]
16 [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
17 public string Id { get; set; }
18
19 [JsonPropertyName("success")]
20 public bool Success { get; init; }
21
22 [JsonPropertyName("message")]
23 public string Message { get; init; }
24
25 [JsonPropertyName("data")]
26 [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
27 public JsonElement? Data { get; init; }
28
29 /// <summary>
30 /// When true, the caller should exit the interactive loop after sending this result.
31 /// Not serialized — this is internal control flow only.
32 /// </summary>
33 [JsonIgnore]
34 public bool IsQuit { get; init; }
35
36 /// <summary>
37 /// Creates a successful result with a message.
38 /// </summary>
39 public static ActionResult Ok(string message) =>
40 new() { Success = true, Message = message };
41
42 /// <summary>
43 /// Creates a successful result with a message and associated data.
44 /// </summary>
45 public static ActionResult Ok(string message, JsonElement data) =>
46 new() { Success = true, Message = message, Data = data };
47
48 /// <summary>
49 /// Creates a failure result with an error message.
50 /// </summary>
51 public static ActionResult Fail(string message) =>
52 new() { Success = false, Message = message };
53
54 /// <summary>
55 /// Creates a successful quit result that signals the interactive loop to exit.
56 /// </summary>
57 public static ActionResult Quit() =>
58 new() { Success = true, Message = "Quitting", IsQuit = true };
59}
60