Skip to content

Commit 674491b

Browse files
committed
fix: configure ProjectR and ProjectR.Generator for NuGet publishing
1 parent 53a7f86 commit 674491b

22 files changed

+179
-82
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Setup .NET
3434
uses: actions/setup-dotnet@v4
3535
with:
36-
dotnet-version: '9.0.x'
36+
dotnet-version: '10.0.x'
3737

3838
# 3. Ripristina le dipendenze NuGet del progetto
3939
- name: Restore dependencies
@@ -54,7 +54,10 @@ jobs:
5454
# 6. Crea i pacchetti NuGet per tutti i progetti nella soluzione
5555
- name: Pack projects
5656
if: startsWith(github.ref, 'refs/tags/v')
57-
run: dotnet pack ProjectR.sln --no-build --configuration Release --output ./packages
57+
run: |
58+
VERSION="${{ github.ref_name }}"
59+
VERSION="${VERSION#v}"
60+
dotnet pack ProjectR.sln --no-build --configuration Release --output ./packages /p:Version=$VERSION
5861
5962
# 7. Pubblica tutti i pacchetti .nupkg creati nel passo precedente
6063
- name: Publish to NuGet

Directory.Build.props

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project>
2+
<PropertyGroup>
3+
<Version>1.0.0</Version>
4+
<Authors>Luca Fabbri</Authors>
5+
<Description>ProjectR: Unopinionated object mapping. No black magic. Just your rules, transparently automated.</Description>
6+
<RepositoryUrl>https://github.com/lucafabbri/ProjectR</RepositoryUrl>
7+
<PackageTags>mapper;lucafabbri</PackageTags>
8+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
9+
<LangVersion>latest</LangVersion>
10+
<Nullable>enable</Nullable>
11+
<ImplicitUsings>enable</ImplicitUsings>
12+
</PropertyGroup>
13+
</Project>

ProjectR/Builders/CodeBuilder.cs renamed to ProjectR.Generator/Builders/CodeBuilder.cs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.CodeAnalysis;
1+
using Microsoft.CodeAnalysis;
22
using Microsoft.CodeAnalysis.CSharp.Syntax;
33
using System.Collections.Generic;
44
using System.Linq;
@@ -284,6 +284,52 @@ private string GetFieldName(INamedTypeSymbol typeSymbol)
284284
}
285285

286286
private void Indent() => _sb.Append(new string(' ', _indentationLevel * 4));
287+
288+
public string BuildSourceForPlaceholder(string mapperName, string namespaceName, MappingPlan projectAsPlan, MappingPlan buildPlan, MappingPlan applyToPlan, HashSet<string> allUsings)
289+
{
290+
var dependencies = GetDependencies(projectAsPlan, buildPlan, applyToPlan);
291+
BuildHeader(namespaceName, allUsings);
292+
BuildClassSignature(mapperName);
293+
if (dependencies.Any())
294+
{
295+
BuildConstructorAndFields(mapperName, dependencies);
296+
}
297+
// For placeholders, we use a dummy symbol reference or similar if needed for BuildXmlDoc,
298+
// but usually we can skip it or use defaults.
299+
// The signature of BuildProjectAsMethod requires INamedTypeSymbol.
300+
// We can fake it or overload BuildProjectAsMethod.
301+
// Since this is a refactor, I won't rewrite CodeBuilder too much.
302+
// I'll skip XML docs for placeholders or use a simplified method.
303+
304+
// BuildProjectAsMethod without xml doc
305+
var sourceTypeName = projectAsPlan.SourceType.ToDisplayString();
306+
var destTypeName = projectAsPlan.DestinationType.ToDisplayString();
307+
308+
Indent(); _sb.AppendLine($"public override {destTypeName} ProjectGenerated({sourceTypeName} source)");
309+
Indent(); _sb.AppendLine("{");
310+
_indentationLevel++;
311+
GenerateNullCheck("source", destTypeName);
312+
GenerateCreationBlock("destination", projectAsPlan.DestinationType, projectAsPlan, "source");
313+
_indentationLevel--;
314+
Indent(); _sb.AppendLine("}");
315+
_sb.AppendLine();
316+
317+
// BuildBuildMethod without xml doc
318+
sourceTypeName = buildPlan.SourceType.ToDisplayString();
319+
destTypeName = buildPlan.DestinationType.ToDisplayString();
320+
321+
Indent(); _sb.AppendLine($"public override {destTypeName} BuildGenerated({sourceTypeName} source)");
322+
Indent(); _sb.AppendLine("{");
323+
_indentationLevel++;
324+
GenerateNullCheck("source", destTypeName);
325+
GenerateCreationBlock("destination", buildPlan.DestinationType, buildPlan, "source", true);
326+
_indentationLevel--;
327+
Indent(); _sb.AppendLine("}");
328+
_sb.AppendLine();
329+
330+
BuildFooter();
331+
return _sb.ToString();
332+
}
333+
287334
}
288335
}
289-

ProjectR/Diagnostic/Diagnostics.cs renamed to ProjectR.Generator/Diagnostic/Diagnostics.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.CodeAnalysis;
1+
using Microsoft.CodeAnalysis;
22

33
namespace ProjectR
44
{
@@ -23,26 +23,25 @@ internal static class Diagnostics
2323
public static readonly DiagnosticDescriptor NoValidCreationMethod = new(
2424
id: "PR0003",
2525
title: "No valid creation method found",
26-
messageFormat: "ProjectR could not find a valid constructor or static factory method to create an instance of '{0}' based on the source type.",
26+
messageFormat: "ProjectR could not find a valid constructor or static factory method to create an instance of '{0}' based on the source type",
2727
category: "ProjectR.Policies",
2828
defaultSeverity: DiagnosticSeverity.Error,
2929
isEnabledByDefault: true);
3030

3131
public static readonly DiagnosticDescriptor UnmappableConstructorParameter = new(
3232
id: "PR0004",
3333
title: "Unmappable constructor parameter",
34-
messageFormat: "The parameter '{0}' of the constructor for '{1}' could not be mapped from any source property.",
34+
messageFormat: "The parameter '{0}' of the constructor for '{1}' could not be mapped from any source property",
3535
category: "ProjectR.Policies",
3636
defaultSeverity: DiagnosticSeverity.Error,
3737
isEnabledByDefault: true);
3838

3939
public static readonly DiagnosticDescriptor UnmappedDestinationProperty = new(
4040
id: "PR0005",
4141
title: "Unmapped destination property",
42-
messageFormat: "The property '{0}' on destination type '{1}' was not mapped.",
42+
messageFormat: "The property '{0}' on destination type '{1}' was not mapped",
4343
category: "ProjectR.Policies",
4444
defaultSeverity: DiagnosticSeverity.Warning,
4545
isEnabledByDefault: true);
4646
}
4747
}
48-

ProjectR/Mapping/MapperGenerator.cs renamed to ProjectR.Generator/Mapping/MapperGenerator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.CodeAnalysis;
1+
using Microsoft.CodeAnalysis;
22
using Microsoft.CodeAnalysis.CSharp;
33
using Microsoft.CodeAnalysis.CSharp.Syntax;
44
using System;
@@ -196,4 +196,3 @@ private static void ProcessMapperClass(Compilation compilation, ClassDeclaration
196196
}
197197
}
198198
}
199-

ProjectR/Mapping/MappingInstruction.cs renamed to ProjectR.Generator/Mapping/MappingInstruction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ProjectR;
1+
namespace ProjectR;
22

33
/// <summary>
44
/// Base class for a single mapping instruction.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.CodeAnalysis;
1+
using Microsoft.CodeAnalysis;
22
using Microsoft.CodeAnalysis.CSharp.Syntax;
33
using System.Collections.Generic;
44

@@ -131,4 +131,3 @@ public CollectionPropertyMapping(IPropertySymbol source, INamedTypeSymbol elemen
131131
}
132132
}
133133
}
134-
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Microsoft.CodeAnalysis;
2+
3+
namespace ProjectR;
4+
5+
/// <summary>
6+
/// Represents mapping a complex object property using another mapper (e.g., Address to AddressDto).
7+
/// </summary>
8+
public class NestedObjectMapperMapping : MappingInstruction
9+
{
10+
public IPropertySymbol SourceProperty { get; set; } = default!;
11+
public IPropertySymbol DestinationProperty { get; set; } = default!;
12+
public INamedTypeSymbol MapperType { get; set; } = default!; // The mapper to use (e.g., AddressMapper)
13+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ProjectR;
1+
namespace ProjectR;
22

33
/// <summary>
44
/// Represents the mapping of a source property to a constructor or method parameter.
@@ -8,10 +8,10 @@ public class ParameterMapping
88
/// <summary>
99
/// Gets or sets the name of the property on the source object.
1010
/// </summary>
11-
public string SourcePropertyName { get; set; }
11+
public string SourcePropertyName { get; set; } = string.Empty;
1212

1313
/// <summary>
1414
/// Gets or sets the name of the parameter on the destination constructor or method.
1515
/// </summary>
16-
public string DestinationParameterName { get; set; }
17-
}
16+
public string DestinationParameterName { get; set; } = string.Empty;
17+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ProjectR;
1+
namespace ProjectR;
22

33
/// <summary>
44
/// Represents the direct mapping of a single property from a source to a destination.
@@ -8,10 +8,10 @@ public class PropertyMapping : MappingInstruction
88
/// <summary>
99
/// Gets or sets the name of the property on the source object.
1010
/// </summary>
11-
public string SourcePropertyName { get; set; }
11+
public string SourcePropertyName { get; set; } = string.Empty;
1212

1313
/// <summary>
1414
/// Gets or sets the name of the property on the destination object.
1515
/// </summary>
16-
public string DestinationPropertyName { get; set; }
16+
public string DestinationPropertyName { get; set; } = string.Empty;
1717
}

0 commit comments

Comments
 (0)