Skip to content

Commit

Permalink
(GH-467) Fix serialization in .NET7
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed Sep 27, 2022
1 parent 7875b5d commit b5875eb
Show file tree
Hide file tree
Showing 2 changed files with 302 additions and 24 deletions.
56 changes: 38 additions & 18 deletions Source/StrongGrid.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,44 @@ class Program
{
static void Main(string[] args)
{
//var baseNamespace = "StrongGrid.Models";
//var allTypes = Assembly
// .GetAssembly(typeof(BaseClient))
// .GetTypes()
// .Where(t => t.IsClass)
// .Where(t => !string.IsNullOrEmpty(t.Namespace))
// .Where(t => t.Namespace.StartsWith(baseNamespace))
// .Where(t => !t.Namespace.StartsWith(baseNamespace + ".Webhooks.InboundEmail")); // Exclude inbound email classes which are deserialized by our WebhookParser

//var typesInBaseNamespace = allTypes
// .Where(t => t.Namespace.Equals(baseNamespace))
// .Select(t => new { Type = t, JsonSerializeAttribute = $"[JsonSerializable(typeof({t.FullName}))]" });

//var typesInSubNamespace = allTypes
// .Where(t => !t.Namespace.Equals(baseNamespace))
// .Select(t => new { Type = t, JsonSerializeAttribute = $"[JsonSerializable(typeof({t.FullName}), TypeInfoPropertyName = \"{t.FullName.Remove(0, baseNamespace.Length + 1).Replace(".", "")}\")]" });

//var result = string.Join("\r\n", typesInBaseNamespace.Union(typesInSubNamespace).OrderBy(t => t.Type.FullName).Select(t => t.JsonSerializeAttribute));
/*
* Handy code to generate the 'JsonSerializable' attributes for StrongGridJsonSerializerContext
var baseNamespace = "StrongGrid.Models";
var allTypes = System.Reflection.Assembly
.GetAssembly(typeof(Client))
.GetTypes()
.Where(t => t.IsClass || t.IsEnum)
.Where(t => !string.IsNullOrEmpty(t.Namespace))
.Where(t => t.Namespace.StartsWith(baseNamespace));
var typesInBaseNamespace = allTypes
.Where(t => t.Namespace.Equals(baseNamespace))
.Select(t => new
{
Type = t,
JsonSerializeAttribute = $"[JsonSerializable(typeof({t.FullName}))]",
JsonSerializeAttributeArray = $"[JsonSerializable(typeof({t.FullName}[]))]",
JsonSerializeAttributeNullable = t.IsEnum ? $"[JsonSerializable(typeof({t.FullName}?))]" : string.Empty,
});
var typesInSubNamespace = allTypes
.Where(t => !t.Namespace.Equals(baseNamespace))
.Select(t => new
{
Type = t,
JsonSerializeAttribute = $"[JsonSerializable(typeof({t.FullName}), TypeInfoPropertyName = \"{t.FullName.Remove(0, baseNamespace.Length + 1).Replace(".", "")}\")]",
JsonSerializeAttributeArray = $"[JsonSerializable(typeof({t.FullName}[]), TypeInfoPropertyName = \"{t.FullName.Remove(0, baseNamespace.Length + 1).Replace(".", "")}Array\")]",
JsonSerializeAttributeNullable = t.IsEnum ? $"[JsonSerializable(typeof({t.FullName}?), TypeInfoPropertyName = \"{t.FullName.Remove(0, baseNamespace.Length + 1).Replace(".", "")}Nullable\")]" : string.Empty,
});
var typesSortedAlphabetically = typesInBaseNamespace.Union(typesInSubNamespace).OrderBy(t => t.Type.FullName);
var simpleAttributes = string.Join("\r\n", typesSortedAlphabetically.Where(t => !string.IsNullOrEmpty(t.JsonSerializeAttribute)).Select(t => t.JsonSerializeAttribute));
var arrayAttributes = string.Join("\r\n", typesSortedAlphabetically.Where(t => !string.IsNullOrEmpty(t.JsonSerializeAttributeArray)).Select(t => t.JsonSerializeAttributeArray));
var nullableAttributes = string.Join("\r\n", typesSortedAlphabetically.Where(t => !string.IsNullOrEmpty(t.JsonSerializeAttributeNullable)).Select(t => t.JsonSerializeAttributeNullable));
var result = string.Join("\r\n\r\n", new[] { simpleAttributes, arrayAttributes, nullableAttributes });
*/

IConfig config = null;

Expand Down
Loading

0 comments on commit b5875eb

Please sign in to comment.