-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
OSOE-795: Upgrade to latest OC preview to test System.Text.Json
- Loading branch information
Showing
29 changed files
with
431 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace System.Text.Json.Nodes; | ||
|
||
public static class JsonNodeExtensions | ||
{ | ||
/// <summary> | ||
/// Checks if the provided <paramref name="node"/> is object and has a <c>Type</c> property, and if its value | ||
/// matches <typeparamref name="T"/>. | ||
/// </summary> | ||
public static bool HasMatchingTypeProperty<T>(this JsonNode node) => | ||
node is JsonObject jsonObject && jsonObject["Type"]?.ToString() == typeof(T).Name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lombiq.DataTables.Models; | ||
|
||
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))] | ||
public class DataTableColumn | ||
{ | ||
[JsonPropertyName("data")] | ||
public string Data { get; set; } | ||
|
||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonPropertyName("searchable")] | ||
public bool Searchable { get; set; } | ||
|
||
[JsonPropertyName("orderable")] | ||
public bool Orderable { get; set; } | ||
|
||
[JsonPropertyName("search")] | ||
public DataTableSearchParameters Search { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
using Lombiq.DataTables.Constants; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lombiq.DataTables.Models; | ||
|
||
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))] | ||
public class DataTableOrder | ||
{ | ||
public string Column { get; set; } | ||
|
||
[JsonIgnore] | ||
public SortingDirection Direction { get; set; } | ||
|
||
[JsonPropertyName("direction")] | ||
[JsonInclude] | ||
[SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "It's used for JSON conversion.")] | ||
private string DirectionString | ||
{ | ||
get => IsAscending ? "ascending" : "descending"; | ||
set => Direction = value == "descending" ? SortingDirection.Descending : SortingDirection.Ascending; | ||
} | ||
|
||
[JsonIgnore] | ||
public bool IsAscending => Direction == SortingDirection.Ascending; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,52 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using Newtonsoft.Json.Serialization; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.Json.Nodes; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lombiq.DataTables.Models; | ||
|
||
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))] | ||
public class DataTableRow | ||
{ | ||
[JsonExtensionData] | ||
internal IDictionary<string, JToken> ValuesDictionary { get; set; } | ||
[JsonInclude] | ||
[JsonPropertyName("valuesDictionary")] | ||
internal IDictionary<string, object> ValuesDictionary { get; set; } = new Dictionary<string, object>(); | ||
|
||
[JsonPropertyName("id")] | ||
public int Id { get; set; } | ||
|
||
public string this[string name] | ||
{ | ||
get => ValuesDictionary.TryGetValue(name, out var value) ? value.Value<string>() : null; | ||
get => ValuesDictionary.GetMaybe(name)?.ToString(); | ||
set => ValuesDictionary[name] = value; | ||
} | ||
|
||
public DataTableRow() => ValuesDictionary = new Dictionary<string, JToken>(); | ||
public DataTableRow() { } | ||
|
||
public DataTableRow(int id, IDictionary<string, JToken> valuesDictionary) | ||
public DataTableRow(int id, IDictionary<string, JsonNode> valuesDictionary) | ||
{ | ||
Id = id; | ||
ValuesDictionary = valuesDictionary; | ||
|
||
if (valuesDictionary != null) | ||
{ | ||
foreach (var (key, value) in valuesDictionary) | ||
{ | ||
ValuesDictionary[key] = value; | ||
} | ||
} | ||
} | ||
|
||
public IEnumerable<string> GetValues() => | ||
ValuesDictionary.Values.Select(value => value.Value<string>()); | ||
ValuesDictionary.Values.Select(value => value.ToString()); | ||
|
||
public IEnumerable<string> GetValuesOrderedByColumns(IEnumerable<DataTableColumnDefinition> columnDefinitions) => | ||
columnDefinitions.Select(columnDefinition => this[columnDefinition.Name] ?? string.Empty); | ||
|
||
internal JsonNode GetValueAsJsonNode(string name) => | ||
ValuesDictionary.GetMaybe(name) switch | ||
{ | ||
JsonNode node => node, | ||
{ } otherValue => JObject.FromObject(otherValue), | ||
null => null, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lombiq.DataTables.Models; | ||
|
||
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))] | ||
public class DataTableSearchParameters | ||
{ | ||
[JsonPropertyName("value")] | ||
public string Value { get; set; } | ||
|
||
[JsonProperty(PropertyName = "regex")] | ||
[JsonPropertyName("regex")] | ||
public bool IsRegex { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.