Hermod
A cross-platform, modular and fully GDPR-compliant email archival solution!
Loading...
Searching...
No Matches
JsonCommandResult.cs
Go to the documentation of this file.
1using System;
2
4
5 using Newtonsoft.Json;
6
7 public class JsonCommandResult<T>: ICommandResult<T> {
8
9 #region ICommandResult
11 public string? Message { get; set; }
12
14 public T Result { get; set; }
15
16 object? ICommandResult.Result => throw new NotImplementedException();
17 #endregion
18
19 public JsonCommandResult(): this(string.Empty, Activator.CreateInstance<T>()) { }
20
21 public JsonCommandResult(string message, T result) {
22 Message = message;
23 Result = result;
24 }
25
31 public string? ToJson(JsonSerializerSettings? settings) => JsonConvert.SerializeObject(Result, settings);
32
38 public string? ToJson(Formatting formatting) => JsonConvert.SerializeObject(Result, formatting);
39 }
40}
41
string? ToJson(JsonSerializerSettings? settings)
Converts the Result to a JSON-serialised string.
string? ToJson(Formatting formatting)
Converts the Result to a JSON-serialised string.
string? Message
An optional message. This message may be written to logs.
T Result
The command's result. The result may be sent over the wire.
A generic, object-based variation of ICommandResult<T>.