Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Rule ID | Category | Severity | Notes
--------|----------|----------|-------
MAPC001 | MapperGenerator | Error | DiagnosticRules
MAPC002 | MapperGenerator | Error | DiagnosticRules
MAPC003 | MapperGenerator | Error | DiagnosticRules
MAPC003 | Mapping | Warning | DiagnosticRules
MAPC004 | MapperGenerator | Error | DiagnosticRules
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
EAppliedOn.Assembly => DiagnosticRules.GenerateMapperTwoParameters.Create(type.TypeToMap.Location),
_ => null,
})
.NotNull();
.NotNull()
.Concat()

Check failure on line 30 in SourceGenerators/Mapper/MintPlayer.Mapper/Generators/MapperGenerator.Producer.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-any

No overload for method 'Concat' takes 0 arguments

Check failure on line 30 in SourceGenerators/Mapper/MintPlayer.Mapper/Generators/MapperGenerator.Producer.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-any

No overload for method 'Concat' takes 0 arguments

Check failure on line 30 in SourceGenerators/Mapper/MintPlayer.Mapper/Generators/MapperGenerator.Producer.cs

View workflow job for this annotation

GitHub Actions / pull-request

No overload for method 'Concat' takes 0 arguments

Check failure on line 30 in SourceGenerators/Mapper/MintPlayer.Mapper/Generators/MapperGenerator.Producer.cs

View workflow job for this annotation

GitHub Actions / pull-request

No overload for method 'Concat' takes 0 arguments
;
}

protected override void ProduceSource(IndentedTextWriter writer, CancellationToken cancellationToken)
Expand Down Expand Up @@ -294,6 +296,9 @@

private static void HandleProperty(IndentedTextWriter writer, PropertyDeclaration source, PropertyDeclaration destination, EWriteType writeType)
{
// Skip init-only properties for assignment
if (destination.IsInitOnly) return;

var prefix = writeType switch
{
EWriteType.Initializer => $"{source.PropertyName} = ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ public static partial class DiagnosticRules
category: "MapperGenerator",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor InitOnlyPropertyNotMapped = new(
id: "MAPC003",
title: "Init-only property not mapped",
messageFormat: "The property '{0}' on type '{1}' is init-only and will not be mapped from '{2}'",
category: "Mapping",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ private static string CreateMethodName(TypedConstant preferred, INamedTypeSymbol
//IsNullable = p.NullableAnnotation == NullableAnnotation.Annotated,
//IsReadOnly = p.IsReadOnly,
IsStatic = p.IsStatic,
IsInitOnly = p.SetMethod is { IsInitOnly: true },
//IsVirtual = p.IsVirtual,
//IsAbstract = p.IsAbstract,
//IsOverride = p.IsOverride,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public partial class PropertyDeclaration
public int? StateName { get; set; }
public bool IsStatic { get; set; }
public bool IsPrimitive { get; set; }
public bool IsInitOnly { get; set; }

public override string ToString() => $"{PropertyName} ({PropertyType})";
}
Loading