Ignore properties with matching names but different types.
This commit is contained in:
parent
f1122af3d1
commit
7b03c7a55e
|
@ -101,11 +101,12 @@ namespace MapTo
|
||||||
{
|
{
|
||||||
return sourceTypeSymbol
|
return sourceTypeSymbol
|
||||||
.GetAllMembersOfType<IPropertySymbol>()
|
.GetAllMembersOfType<IPropertySymbol>()
|
||||||
.Select(p => p.Name)
|
.Select(p => (p.Name, p.Type.ToString()))
|
||||||
.Intersect(classSymbol
|
.Intersect(classSymbol
|
||||||
.GetAllMembersOfType<IPropertySymbol>()
|
.GetAllMembersOfType<IPropertySymbol>()
|
||||||
.Where(p => p.GetAttributes().All(a => a.AttributeClass?.Name != SourceBuilder.IgnorePropertyAttributeName))
|
.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();
|
.ToImmutableArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -413,5 +413,39 @@ namespace MapTo
|
||||||
diagnostics.ShouldBeSuccessful();
|
diagnostics.ShouldBeSuccessful();
|
||||||
compilation.SyntaxTrees.Last().ToString().ShouldContain(expectedResult);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue