Fix UseUpdate usage

This commit is contained in:
Wvader 2022-08-20 03:47:55 +01:00
parent f7963d2d7e
commit aa5b01cdc4
3 changed files with 19 additions and 25 deletions

View File

@ -13,7 +13,7 @@ namespace MapTo.Extensions
{ {
internal static SourceCode GenerateStructOrClass(this MappingModel model, string structOrClass) internal static SourceCode GenerateStructOrClass(this MappingModel model, string structOrClass)
{ {
const bool writeDebugInfo = true; const bool writeDebugInfo = false;
using var builder = new SourceBuilder() using var builder = new SourceBuilder()
@ -58,12 +58,10 @@ namespace MapTo.Extensions
.WriteLine() .WriteLine()
// Class body // Class body
.GeneratePublicConstructor(model); .GeneratePublicConstructor(model);
foreach (var targetSourceType in model.MappedSourceTypes)
{
if (model.IsTypeUpdatable && targetSourceType.TypeProperties.GetWritableMappedProperties().Length > 0) builder.GenerateUpdateMethod(model);
if (model.IsTypeUpdatable && targetSourceType.TypeFields.GetWritableMappedProperties().Length > 0) builder.GenerateUpdateMethod(model);
}
var addedMembers = new List<MappedMember>();
if (model.IsTypeUpdatable) builder.GenerateUpdateMethod(model);
if (model.IsJsonExtension) builder.WriteToJsonMethod(model); if (model.IsJsonExtension) builder.WriteToJsonMethod(model);
@ -116,7 +114,8 @@ namespace MapTo.Extensions
.WriteOpeningBracket() .WriteOpeningBracket()
.WriteAssignmentMethod(model, otherProperties.ToArray().ToImmutableArray(), sourceClassParameterName, mappingContextParameterName, false); .WriteAssignmentMethod(model, otherProperties.ToArray().ToImmutableArray(), sourceClassParameterName, mappingContextParameterName, false);
builder.WriteClosingBracket(); builder.WriteClosingBracket()
.WriteLine();
} }
// End constructor declaration // End constructor declaration
@ -302,35 +301,31 @@ namespace MapTo.Extensions
var sourceClassParameterName = targetSourceType.SourceTypeIdentifierName.ToCamelCase(); var sourceClassParameterName = targetSourceType.SourceTypeIdentifierName.ToCamelCase();
builder builder
.GenerateUpdaterMethodsXmlDocs(model, sourceClassParameterName) .GenerateUpdaterMethodsXmlDocs(model, sourceClassParameterName, targetSourceType)
.WriteLine($"public void Update({targetSourceType.SourceType} {sourceClassParameterName})") .WriteLine($"public void Update({targetSourceType.SourceType} {sourceClassParameterName})")
.WriteOpeningBracket() .WriteOpeningBracket()
.WriteAssignmentMethod(model, null, sourceClassParameterName, "context", true) .WriteAssignmentMethod(model, null, sourceClassParameterName, "context", true)
.WriteClosingBracket(); .WriteClosingBracket()
.WriteLine();
} }
return builder; return builder;
} }
private static SourceBuilder GenerateUpdaterMethodsXmlDocs(this SourceBuilder builder, MappingModel model, string sourceClassParameterName) private static SourceBuilder GenerateUpdaterMethodsXmlDocs(this SourceBuilder builder, MappingModel model, string sourceClassParameterName,
MappedSourceType mappedSourceType)
{ {
if (!model.Options.GenerateXmlDocument) if (!model.Options.GenerateXmlDocument)
{ {
return builder; return builder;
} }
builder
foreach (var targetSourceType in model.MappedSourceTypes) .WriteLine("/// <summary>")
{ .WriteLine($"/// Updates <see cref=\"{model.TypeIdentifierName}\"/> and sets its participating properties")
builder .WriteLine($"/// using the property values from <paramref name=\"{sourceClassParameterName}\"/>.")
.WriteLine("/// <summary>") .WriteLine("/// </summary>")
.WriteLine($"/// Updates <see cref=\"{model.TypeIdentifierName}\"/> and sets its participating properties") .WriteLine($"/// <param name=\"{sourceClassParameterName}\">The instance of <see cref=\"{mappedSourceType.SourceType}\"/> to use as source.</param>");
.WriteLine($"/// using the property values from <paramref name=\"{sourceClassParameterName}\"/>.")
.WriteLine("/// </summary>")
.WriteLine($"/// <param name=\"{sourceClassParameterName}\">The instance of <see cref=\"{targetSourceType.SourceType}\"/> to use as source.</param>");
}
return builder; return builder;
} }

View File

@ -1,9 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading;
using MapTo.Extensions; using MapTo.Extensions;
using MapTo.Sources; using MapTo.Sources;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
@ -507,7 +505,7 @@ namespace MapTo
var typeIdentifierName = TypeSyntax.GetIdentifierName(); var typeIdentifierName = TypeSyntax.GetIdentifierName();
var isTypeInheritFromMappedBaseClass = IsTypeInheritFromMappedBaseClass(semanticModel); var isTypeInheritFromMappedBaseClass = IsTypeInheritFromMappedBaseClass(semanticModel);
var isTypeUpdatable = false; //IsTypeUpdatable(); var isTypeUpdatable = true; //IsTypeUpdatable();
var hasJsonExtension = false; // HasJsonExtension(); var hasJsonExtension = false; // HasJsonExtension();
List<MappedSourceType> mappedSourceTypes = new List<MappedSourceType>(); List<MappedSourceType> mappedSourceTypes = new List<MappedSourceType>();

View File

@ -23,6 +23,7 @@ namespace MapTo.Sources
if (options.GenerateXmlDocument) if (options.GenerateXmlDocument)
{ {
builder builder
.WriteLine()
.WriteLine("/// <summary>") .WriteLine("/// <summary>")
.WriteLine("/// Specifies the mapping behavior of the annotated property.") .WriteLine("/// Specifies the mapping behavior of the annotated property.")
.WriteLine("/// </summary>") .WriteLine("/// </summary>")