From aa5b01cdc42a00e873f126049a9c111b1d5220fa Mon Sep 17 00:00:00 2001 From: Wvader <34067397+wvader@users.noreply.github.com> Date: Sat, 20 Aug 2022 03:47:55 +0100 Subject: [PATCH] Fix UseUpdate usage --- src/BlueWest.MapTo/Extensions/CommonSource.cs | 39 ++++++++----------- src/BlueWest.MapTo/MappingContext.cs | 4 +- .../Sources/MapPropertyAttributeSource.cs | 1 + 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/BlueWest.MapTo/Extensions/CommonSource.cs b/src/BlueWest.MapTo/Extensions/CommonSource.cs index 0b58acd..b804eed 100644 --- a/src/BlueWest.MapTo/Extensions/CommonSource.cs +++ b/src/BlueWest.MapTo/Extensions/CommonSource.cs @@ -13,7 +13,7 @@ namespace MapTo.Extensions { internal static SourceCode GenerateStructOrClass(this MappingModel model, string structOrClass) { - const bool writeDebugInfo = true; + const bool writeDebugInfo = false; using var builder = new SourceBuilder() @@ -58,12 +58,10 @@ namespace MapTo.Extensions .WriteLine() // Class body .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(); + + if (model.IsTypeUpdatable) builder.GenerateUpdateMethod(model); if (model.IsJsonExtension) builder.WriteToJsonMethod(model); @@ -116,7 +114,8 @@ namespace MapTo.Extensions .WriteOpeningBracket() .WriteAssignmentMethod(model, otherProperties.ToArray().ToImmutableArray(), sourceClassParameterName, mappingContextParameterName, false); - builder.WriteClosingBracket(); + builder.WriteClosingBracket() + .WriteLine(); } // End constructor declaration @@ -302,35 +301,31 @@ namespace MapTo.Extensions var sourceClassParameterName = targetSourceType.SourceTypeIdentifierName.ToCamelCase(); builder - .GenerateUpdaterMethodsXmlDocs(model, sourceClassParameterName) + .GenerateUpdaterMethodsXmlDocs(model, sourceClassParameterName, targetSourceType) .WriteLine($"public void Update({targetSourceType.SourceType} {sourceClassParameterName})") .WriteOpeningBracket() .WriteAssignmentMethod(model, null, sourceClassParameterName, "context", true) - .WriteClosingBracket(); + .WriteClosingBracket() + .WriteLine(); } 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) { return builder; } - - foreach (var targetSourceType in model.MappedSourceTypes) - { - builder - .WriteLine("/// ") - .WriteLine($"/// Updates and sets its participating properties") - .WriteLine($"/// using the property values from .") - .WriteLine("/// ") - .WriteLine($"/// The instance of to use as source."); - - } - + builder + .WriteLine("/// ") + .WriteLine($"/// Updates and sets its participating properties") + .WriteLine($"/// using the property values from .") + .WriteLine("/// ") + .WriteLine($"/// The instance of to use as source."); return builder; } diff --git a/src/BlueWest.MapTo/MappingContext.cs b/src/BlueWest.MapTo/MappingContext.cs index e7b7fdd..1f02b39 100644 --- a/src/BlueWest.MapTo/MappingContext.cs +++ b/src/BlueWest.MapTo/MappingContext.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Diagnostics; using System.Linq; -using System.Threading; using MapTo.Extensions; using MapTo.Sources; using Microsoft.CodeAnalysis; @@ -507,7 +505,7 @@ namespace MapTo var typeIdentifierName = TypeSyntax.GetIdentifierName(); var isTypeInheritFromMappedBaseClass = IsTypeInheritFromMappedBaseClass(semanticModel); - var isTypeUpdatable = false; //IsTypeUpdatable(); + var isTypeUpdatable = true; //IsTypeUpdatable(); var hasJsonExtension = false; // HasJsonExtension(); List mappedSourceTypes = new List(); diff --git a/src/BlueWest.MapTo/Sources/MapPropertyAttributeSource.cs b/src/BlueWest.MapTo/Sources/MapPropertyAttributeSource.cs index 4c18cae..2337997 100644 --- a/src/BlueWest.MapTo/Sources/MapPropertyAttributeSource.cs +++ b/src/BlueWest.MapTo/Sources/MapPropertyAttributeSource.cs @@ -23,6 +23,7 @@ namespace MapTo.Sources if (options.GenerateXmlDocument) { builder + .WriteLine() .WriteLine("/// ") .WriteLine("/// Specifies the mapping behavior of the annotated property.") .WriteLine("/// ")