diff --git a/src/MapTo/MapToGenerator.cs b/src/MapTo/MapToGenerator.cs index 1d9c71a..69f155f 100644 --- a/src/MapTo/MapToGenerator.cs +++ b/src/MapTo/MapToGenerator.cs @@ -101,11 +101,12 @@ namespace MapTo { return sourceTypeSymbol .GetAllMembersOfType() - .Select(p => p.Name) + .Select(p => (p.Name, p.Type.ToString())) .Intersect(classSymbol .GetAllMembersOfType() .Where(p => p.GetAttributes().All(a => a.AttributeClass?.Name != SourceBuilder.IgnorePropertyAttributeName)) - .Select(p => p.Name)) + .Select(p => (p.Name, p.Type.ToString()))) + .Select(p => p.Name) .ToImmutableArray(); } } diff --git a/test/MapTo.Tests/Tests.cs b/test/MapTo.Tests/Tests.cs index 0f4499a..037c093 100644 --- a/test/MapTo.Tests/Tests.cs +++ b/test/MapTo.Tests/Tests.cs @@ -413,5 +413,39 @@ namespace MapTo diagnostics.ShouldBeSuccessful(); compilation.SyntaxTrees.Last().ToString().ShouldContain(expectedResult); } + + [Fact] + public void When_FoundMatchingPropertyNameWithDifferentType_Should_Ignore() + { + // Arrange + var source = GetSourceText(new SourceGeneratorOptions( + UseMapToNamespace: true, + PropertyBuilder: builder => + { + builder + .PadLeft(Indent2).AppendLine("public string Prop4 { get; set; }"); + }, + SourcePropertyBuilder: builder => builder.PadLeft(Indent2).AppendLine("public int Prop4 { get; set; }"))); + + var expectedResult = @" + public partial class Foo + { + public Foo(Test.Models.Baz baz) + { + if (baz == null) throw new ArgumentNullException(nameof(baz)); + + Prop1 = baz.Prop1; + Prop2 = baz.Prop2; + Prop3 = baz.Prop3; + } +".Trim(); + + // Act + var (compilation, diagnostics) = CSharpGenerator.GetOutputCompilation(source); + + // Assert + diagnostics.ShouldBeSuccessful(); + compilation.SyntaxTrees.Last().ToString().ShouldContain(expectedResult); + } } } \ No newline at end of file