Skip to content

Commit 45abe2a

Browse files
authored
refactor(core): types and utilities (#2)
1 parent 2b92768 commit 45abe2a

File tree

113 files changed

+3743
-2993
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+3743
-2993
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ jobs:
3232
shell: bash
3333
run: dotnet build ./all.csproj -f net${{ matrix.dotnet-version }}.0
3434

35+
- name: Check for breaking API changes
36+
shell: bash
37+
run: dotnet build src/Yamlify/Yamlify.csproj --no-restore -warnaserror:RS0016,RS0017
38+
3539
- name: Run tests
3640
shell: bash
3741
run: dotnet test ./all.csproj /p:BuildTestsOnly=true --no-build -f net${{ matrix.dotnet-version }}.0 -- RunConfiguration.MaxCpuCount=1

Directory.Build.props

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<!-- Common build settings -->
5+
<LangVersion>preview</LangVersion>
6+
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
9+
<WarningsAsErrors>$(WarningsAsErrors);nullable</WarningsAsErrors>
10+
</PropertyGroup>
11+
12+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
13+
<DebugType>full</DebugType>
14+
<DebugSymbols>true</DebugSymbols>
15+
</PropertyGroup>
16+
17+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
18+
<DebugType>pdbonly</DebugType>
19+
<DebugSymbols>true</DebugSymbols>
20+
</PropertyGroup>
21+
22+
<PropertyGroup>
23+
<!-- Package metadata -->
24+
<Version Condition="$(Version) == ''">0.0.0</Version>
25+
<Product>Yamlify</Product>
26+
<Authors>SwissLife-OSS</Authors>
27+
<Company>Swiss Life</Company>
28+
<Copyright>Copyright © $(Company) $([System.DateTime]::Now.Year)</Copyright>
29+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
30+
<PackageProjectUrl>https://github.com/SwissLife-OSS/Yamlify</PackageProjectUrl>
31+
<PackageReleaseNotes>Release notes: https://github.com/SwissLife-OSS/Yamlify/releases/$(Version)</PackageReleaseNotes>
32+
</PropertyGroup>
33+
34+
<PropertyGroup>
35+
<!-- Source Link and symbols -->
36+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
37+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
38+
<RepositoryUrl>https://github.com/SwissLife-OSS/Yamlify.git</RepositoryUrl>
39+
<RepositoryType>git</RepositoryType>
40+
<IncludeSymbols>true</IncludeSymbols>
41+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
42+
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
43+
</PropertyGroup>
44+
45+
<ItemGroup>
46+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
47+
</ItemGroup>
48+
49+
</Project>

nuget.config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<clear />
5+
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
6+
</packageSources>
7+
</configuration>

src/Yamlify.SourceGenerator/YamlSourceGenerator.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private static bool IsCandidateClass(SyntaxNode node)
8484
var indentSequenceItems = true;
8585
var ignoreNullValues = false;
8686
var ignoreEmptyObjects = false;
87-
var discriminatorPosition = DiscriminatorPositionMode.Ordered;
87+
var discriminatorPosition = DiscriminatorPositionMode.PropertyOrder;
8888

8989
foreach (var attributeData in classSymbol.GetAttributes())
9090
{
@@ -248,7 +248,7 @@ private static string GenerateContextSource(ContextToGenerate ctx, Compilation c
248248
sb.AppendLine();
249249
sb.AppendLine("using System;");
250250
sb.AppendLine("using System.Collections.Generic;");
251-
sb.AppendLine("using Yamlify.Core;");
251+
sb.AppendLine("using Yamlify;");
252252
sb.AppendLine("using Yamlify.Serialization;");
253253
sb.AppendLine();
254254

@@ -369,7 +369,7 @@ private static void GenerateTypeInfoMethod(StringBuilder sb, TypeToGenerate type
369369

370370
sb.AppendLine($" properties.Add(new YamlPropertyInfo<{fullTypeName}, {propTypeName}>(");
371371
sb.AppendLine($" name: \"{propName}\",");
372-
sb.AppendLine($" yamlPropertyName: \"{yamlName}\",");
372+
sb.AppendLine($" serializedName: \"{yamlName}\",");
373373

374374
if (prop.GetMethod is not null)
375375
{
@@ -1481,11 +1481,11 @@ private static void GenerateWriteMethod(StringBuilder sb, TypeToGenerate type, I
14811481

14821482
// Write discriminator at the beginning if:
14831483
// 1. DiscriminatorPosition.First is configured, OR
1484-
// 2. DiscriminatorPosition.Ordered is configured but there's no matching property to attach the order to
1484+
// 2. DiscriminatorPosition.PropertyOrder is configured but there's no matching property to attach the order to
14851485
if (discriminatorPropertyName is not null && discriminatorValue is not null)
14861486
{
14871487
var shouldWriteDiscriminatorFirst = discriminatorPosition == DiscriminatorPositionMode.First
1488-
|| (discriminatorPosition == DiscriminatorPositionMode.Ordered && !discriminatorHasMatchingProperty);
1488+
|| (discriminatorPosition == DiscriminatorPositionMode.PropertyOrder && !discriminatorHasMatchingProperty);
14891489

14901490
if (shouldWriteDiscriminatorFirst)
14911491
{
@@ -1552,7 +1552,7 @@ private static void GenerateWriteMethod(StringBuilder sb, TypeToGenerate type, I
15521552
if (isDiscriminatorProperty)
15531553
{
15541554
// When DiscriminatorPosition.First (or no matching property), discriminator was already written - skip
1555-
// When DiscriminatorPosition.Ordered AND there IS a matching property, write the discriminator at this position
1555+
// When DiscriminatorPosition.PropertyOrder AND there IS a matching property, write the discriminator at this position
15561556
if (discriminatorPosition == DiscriminatorPositionMode.First || !discriminatorHasMatchingProperty)
15571557
{
15581558
continue;
@@ -2000,7 +2000,7 @@ private static void GeneratePropertyWrite(StringBuilder sb, string propName, ITy
20002000
sb.AppendLine($"{indent}{{");
20012001
sb.AppendLine($"{indent2}writer.WriteNull();");
20022002
sb.AppendLine($"{indent}}}");
2003-
sb.AppendLine($"{indent}else if (YamlSerializerOptions.IsAlreadySerialized(value.{propName}))");
2003+
sb.AppendLine($"{indent}else if (YamlSerializerOptions.CurrentResolver?.IsCycleReference(value.{propName}) == true)");
20042004
sb.AppendLine($"{indent}{{");
20052005
sb.AppendLine($"{indent2}// Circular reference detected - write null to break the cycle");
20062006
sb.AppendLine($"{indent2}writer.WriteNull();");
@@ -3088,7 +3088,7 @@ private static void GenerateCollectionWrite(StringBuilder sb, string propName, I
30883088
// Use flow style for empty collections to output [] instead of nothing
30893089
sb.AppendLine($" if (value.{propName} is System.Collections.ICollection {{ Count: 0 }})");
30903090
sb.AppendLine(" {");
3091-
sb.AppendLine(" writer.WriteSequenceStart(Yamlify.Core.CollectionStyle.Flow);");
3091+
sb.AppendLine(" writer.WriteSequenceStart(Yamlify.CollectionStyle.Flow);");
30923092
sb.AppendLine(" writer.WriteSequenceEnd();");
30933093
sb.AppendLine(" }");
30943094
sb.AppendLine(" else");
@@ -3203,7 +3203,7 @@ private static void GenerateElementWrite(StringBuilder sb, string varName, IType
32033203
sb.AppendLine($"{indent}{{");
32043204
sb.AppendLine($"{indent} writer.WriteNull();");
32053205
sb.AppendLine($"{indent}}}");
3206-
sb.AppendLine($"{indent}else if (YamlSerializerOptions.IsAlreadySerialized({varName}))");
3206+
sb.AppendLine($"{indent}else if (YamlSerializerOptions.CurrentResolver?.IsCycleReference({varName}) == true)");
32073207
sb.AppendLine($"{indent}{{");
32083208
sb.AppendLine($"{indent} // Circular reference detected - write null to break the cycle");
32093209
sb.AppendLine($"{indent} writer.WriteNull();");
@@ -3432,7 +3432,7 @@ public ContextToGenerate(
34323432
bool indentSequenceItems = true,
34333433
bool ignoreNullValues = false,
34343434
bool ignoreEmptyObjects = false,
3435-
DiscriminatorPositionMode discriminatorPosition = DiscriminatorPositionMode.Ordered)
3435+
DiscriminatorPositionMode discriminatorPosition = DiscriminatorPositionMode.PropertyOrder)
34363436
{
34373437
ClassName = className;
34383438
Namespace = ns;
@@ -3487,7 +3487,7 @@ internal enum DiscriminatorPositionMode
34873487
/// <summary>
34883488
/// The discriminator property is written according to its YamlPropertyOrder or declaration order.
34893489
/// </summary>
3490-
Ordered = 0,
3490+
PropertyOrder = 0,
34913491

34923492
/// <summary>
34933493
/// The discriminator property is always written first.

src/Yamlify.SourceGenerator/Yamlify.SourceGenerator.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<LangVersion>12.0</LangVersion>
6-
<Nullable>enable</Nullable>
7-
<WarningsAsErrors>$(WarningsAsErrors);nullable</WarningsAsErrors>
86
<ImplicitUsings>disable</ImplicitUsings>
97
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
108
<IsRoslynComponent>true</IsRoslynComponent>
119

12-
<!-- Package metadata - not published separately, bundled with Yamlify -->
10+
<!-- Not published separately, bundled with Yamlify -->
1311
<IsPackable>false</IsPackable>
1412

1513
<!-- Suppress analyzer release tracking warning (bundled with main package) -->
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace Yamlify;
2+
3+
/// <summary>
4+
/// Specifies the collection style used in YAML presentation.
5+
/// </summary>
6+
public enum CollectionStyle : byte
7+
{
8+
/// <summary>
9+
/// Any style (for reader) or auto-detect best style (for writer).
10+
/// </summary>
11+
Any = 0,
12+
13+
/// <summary>
14+
/// Block style using indentation.
15+
/// </summary>
16+
Block,
17+
18+
/// <summary>
19+
/// Flow style using explicit indicators ([], {}).
20+
/// </summary>
21+
Flow
22+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Yamlify.Core;
1+
namespace Yamlify;
22

33
/// <summary>
44
/// Represents a position within a YAML stream, including line and column information.

src/Yamlify/Common/ScalarStyle.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace Yamlify;
2+
3+
/// <summary>
4+
/// Specifies the scalar style used in YAML presentation.
5+
/// </summary>
6+
public enum ScalarStyle : byte
7+
{
8+
/// <summary>
9+
/// Any style (for reader) or auto-detect best style (for writer).
10+
/// </summary>
11+
Any = 0,
12+
13+
/// <summary>
14+
/// Plain (unquoted) scalar style.
15+
/// </summary>
16+
Plain,
17+
18+
/// <summary>
19+
/// Single-quoted scalar style ('value').
20+
/// </summary>
21+
SingleQuoted,
22+
23+
/// <summary>
24+
/// Double-quoted scalar style ("value").
25+
/// </summary>
26+
DoubleQuoted,
27+
28+
/// <summary>
29+
/// Literal block scalar style (|).
30+
/// </summary>
31+
Literal,
32+
33+
/// <summary>
34+
/// Folded block scalar style (>).
35+
/// </summary>
36+
Folded
37+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Yamlify.Core;
1+
namespace Yamlify;
22

33
/// <summary>
44
/// Specifies the type of YAML token encountered by the <see cref="Utf8YamlReader"/>.

src/Yamlify/Core/YamlStyles.cs

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

0 commit comments

Comments
 (0)