Skip to content

Commit 9ad2ff0

Browse files
committed
fix serde dups
1 parent 18ba49a commit 9ad2ff0

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/cs/Bootsharp.Publish/Common/TypeConverter/TypeCrawler.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ internal sealed class TypeCrawler
99
public void Crawl (Type type)
1010
{
1111
if (!ShouldCrawl(type)) return;
12-
type = GetUnderlyingType(type);
13-
if (!crawled.Add(type)) return;
14-
CrawlProperties(type);
15-
CrawlBaseType(type);
12+
var underlyingType = GetUnderlyingType(type);
13+
if (!crawled.Add(underlyingType)) return;
14+
CrawlProperties(underlyingType);
15+
CrawlBaseType(underlyingType);
16+
crawled.Add(type);
1617
}
1718

1819
private bool ShouldCrawl (Type type)

src/cs/Bootsharp.Publish/Emit/SerializerGenerator.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ internal sealed class SerializerGenerator
1111

1212
public string Generate (SolutionInspection inspection)
1313
{
14-
CollectAttributes(inspection);
15-
CollectDuplicates(inspection);
14+
CollectTopLevel(inspection);
15+
CollectCrawled(inspection);
1616
if (attributes.Count == 0) return "";
1717
return
1818
$"""
@@ -30,7 +30,7 @@ internal partial class SerializerContext : JsonSerializerContext;
3030
""";
3131
}
3232

33-
private void CollectAttributes (SolutionInspection inspection)
33+
private void CollectTopLevel (SolutionInspection inspection)
3434
{
3535
var metas = inspection.StaticMethods
3636
.Concat(inspection.StaticInterfaces.SelectMany(i => i.Methods))
@@ -53,11 +53,10 @@ private void CollectFromValue (ValueMeta meta)
5353
attributes.Add(BuildAttribute(meta.Type));
5454
}
5555

56-
private void CollectDuplicates (SolutionInspection inspection)
56+
private void CollectCrawled (SolutionInspection inspection)
5757
{
58-
var names = new HashSet<string>();
59-
foreach (var type in inspection.Crawled.DistinctBy(t => t.FullName))
60-
if (ShouldSerialize(type) && !names.Add(type.Name))
58+
foreach (var type in inspection.Crawled)
59+
if (ShouldSerialize(type))
6160
attributes.Add(BuildAttribute(type));
6261
}
6362

src/cs/Bootsharp.Publish/Pack/DeclarationGenerator/TypeDeclarationGenerator.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal sealed class TypeDeclarationGenerator (Preferences prefs)
2020
public string Generate (SolutionInspection inspection)
2121
{
2222
instanced = [..inspection.InstancedInterfaces];
23-
types = inspection.Crawled.OrderBy(GetNamespace).ToArray();
23+
types = inspection.Crawled.Where(FilterCrawled).OrderBy(GetNamespace).ToArray();
2424
for (index = 0; index < types.Length; index++)
2525
DeclareType();
2626
return builder.ToString();
@@ -32,6 +32,11 @@ private Type GetTypeAt (int index)
3232
return type.IsGenericType ? type.GetGenericTypeDefinition() : type;
3333
}
3434

35+
private bool FilterCrawled (Type type)
36+
{
37+
return !IsList(type) && !IsCollection(type) && !IsNullable(type);
38+
}
39+
3540
private void DeclareType ()
3641
{
3742
if (ShouldOpenNamespace()) OpenNamespace();

0 commit comments

Comments
 (0)