Skip to content

Commit fc10290

Browse files
committed
Breaking change: remove duplicate TOML attribute (#116)
1 parent 1f12289 commit fc10290

File tree

4 files changed

+56
-31
lines changed

4 files changed

+56
-31
lines changed

site/docs/serialization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ so you can reuse models across JSON and TOML. When both are present, the TOML-sp
206206

207207
| Attribute | JSON equivalent | Description |
208208
| --- | --- | --- |
209-
| [`TomlPropertyNameAttribute`](xref:Tomlyn.TomlPropertyNameAttribute) | [`JsonPropertyNameAttribute`](xref:System.Text.Json.Serialization.JsonPropertyNameAttribute) | Overrides the serialized key name. |
209+
| [`TomlPropertyNameAttribute`](xref:Tomlyn.Serialization.TomlPropertyNameAttribute) | [`JsonPropertyNameAttribute`](xref:System.Text.Json.Serialization.JsonPropertyNameAttribute) | Overrides the serialized key name. |
210210
| [`TomlIgnoreAttribute`](xref:Tomlyn.Serialization.TomlIgnoreAttribute) | [`JsonIgnoreAttribute`](xref:System.Text.Json.Serialization.JsonIgnoreAttribute) | Ignores the member. Supports conditions (`Never`, `WhenWritingNull`, `WhenWritingDefault`). |
211211
| [`TomlIncludeAttribute`](xref:Tomlyn.Serialization.TomlIncludeAttribute) | [`JsonIncludeAttribute`](xref:System.Text.Json.Serialization.JsonIncludeAttribute) | Includes non-public members. |
212212
| [`TomlPropertyOrderAttribute`](xref:Tomlyn.Serialization.TomlPropertyOrderAttribute) | [`JsonPropertyOrderAttribute`](xref:System.Text.Json.Serialization.JsonPropertyOrderAttribute) | Controls ordering within tables. |

site/docs/source-generation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ internal partial class MyTomlContext : TomlSerializerContext { }
9191

9292
For source generation, member names are resolved **at build time** using:
9393

94-
1. [`TomlPropertyNameAttribute`](xref:Tomlyn.TomlPropertyNameAttribute) / [`JsonPropertyNameAttribute`](xref:System.Text.Json.Serialization.JsonPropertyNameAttribute) (when present - these override naming policies).
94+
1. [`TomlPropertyNameAttribute`](xref:Tomlyn.Serialization.TomlPropertyNameAttribute) / [`JsonPropertyNameAttribute`](xref:System.Text.Json.Serialization.JsonPropertyNameAttribute) (when present - these override naming policies).
9595
2. [`TomlSourceGenerationOptionsAttribute.PropertyNamingPolicy`](xref:Tomlyn.Serialization.TomlSourceGenerationOptionsAttribute) (when no explicit name attribute).
9696

9797
The generated serializer stores the resolved names directly and does **not** call `ConvertName(...)` at runtime.
@@ -102,7 +102,7 @@ The source generator supports these attributes at compile time:
102102

103103
| Member-level | Type-level |
104104
| --- | --- |
105-
| [`JsonPropertyNameAttribute`](xref:System.Text.Json.Serialization.JsonPropertyNameAttribute) / [`TomlPropertyNameAttribute`](xref:Tomlyn.TomlPropertyNameAttribute) | [`JsonConstructorAttribute`](xref:System.Text.Json.Serialization.JsonConstructorAttribute) / [`TomlConstructorAttribute`](xref:Tomlyn.Serialization.TomlConstructorAttribute) |
105+
| [`JsonPropertyNameAttribute`](xref:System.Text.Json.Serialization.JsonPropertyNameAttribute) / [`TomlPropertyNameAttribute`](xref:Tomlyn.Serialization.TomlPropertyNameAttribute) | [`JsonConstructorAttribute`](xref:System.Text.Json.Serialization.JsonConstructorAttribute) / [`TomlConstructorAttribute`](xref:Tomlyn.Serialization.TomlConstructorAttribute) |
106106
| [`JsonIgnoreAttribute`](xref:System.Text.Json.Serialization.JsonIgnoreAttribute) / [`TomlIgnoreAttribute`](xref:Tomlyn.Serialization.TomlIgnoreAttribute) | [`JsonPolymorphicAttribute`](xref:System.Text.Json.Serialization.JsonPolymorphicAttribute) / [`TomlPolymorphicAttribute`](xref:Tomlyn.Serialization.TomlPolymorphicAttribute) |
107107
| [`JsonIncludeAttribute`](xref:System.Text.Json.Serialization.JsonIncludeAttribute) / [`TomlIncludeAttribute`](xref:Tomlyn.Serialization.TomlIncludeAttribute) | [`JsonDerivedTypeAttribute`](xref:System.Text.Json.Serialization.JsonDerivedTypeAttribute) / [`TomlDerivedTypeAttribute`](xref:Tomlyn.Serialization.TomlDerivedTypeAttribute) |
108108
| [`JsonPropertyOrderAttribute`](xref:System.Text.Json.Serialization.JsonPropertyOrderAttribute) / [`TomlPropertyOrderAttribute`](xref:Tomlyn.Serialization.TomlPropertyOrderAttribute) | |
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Linq;
3+
using NUnit.Framework;
4+
using Tomlyn.Serialization;
5+
6+
namespace Tomlyn.Tests;
7+
8+
public class NewApiAttributeContractTests
9+
{
10+
[Test]
11+
public void ExportedTomlAttributes_HaveUniqueTypeNames()
12+
{
13+
var duplicateNames = typeof(TomlSerializer).Assembly
14+
.GetExportedTypes()
15+
.Where(static type => type.Name.StartsWith("Toml", StringComparison.Ordinal) &&
16+
type.Name.EndsWith("Attribute", StringComparison.Ordinal))
17+
.GroupBy(static type => type.Name, StringComparer.Ordinal)
18+
.Where(static group => group.Count() > 1)
19+
.Select(static group => group.Key)
20+
.ToArray();
21+
22+
Assert.That(duplicateNames, Is.Empty);
23+
}
24+
25+
[Test]
26+
public void ExportedTomlAttributes_InheritTomlAttribute()
27+
{
28+
var nonDerivedAttributes = typeof(TomlSerializer).Assembly
29+
.GetExportedTypes()
30+
.Where(static type => type != typeof(TomlAttribute) &&
31+
type.IsSubclassOf(typeof(Attribute)) &&
32+
type.Name.StartsWith("Toml", StringComparison.Ordinal) &&
33+
type.Name.EndsWith("Attribute", StringComparison.Ordinal))
34+
.Where(static type => !typeof(TomlAttribute).IsAssignableFrom(type))
35+
.Select(static type => type.FullName)
36+
.ToArray();
37+
38+
Assert.That(nonDerivedAttributes, Is.Empty);
39+
}
40+
41+
[Test]
42+
public void TomlPropertyNameAttribute_IsOnlyAvailableFromSerializationNamespace()
43+
{
44+
var exportedTypes = typeof(TomlSerializer).Assembly
45+
.GetExportedTypes()
46+
.Where(static type => type.Name == nameof(TomlPropertyNameAttribute))
47+
.Select(static type => type.FullName)
48+
.OrderBy(static fullName => fullName, StringComparer.Ordinal)
49+
.ToArray();
50+
51+
Assert.That(exportedTypes, Is.EqualTo(new[] { "Tomlyn.Serialization.TomlPropertyNameAttribute" }));
52+
}
53+
}

src/Tomlyn/TomlPropertyNameAttribute.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)