Skip to content
Merged
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 @@ -146,7 +146,7 @@ static bool IsRecordType(Type type)
{
// Based on the state of the art as described in https://github.com/dotnet/roslyn/issues/45777
var cloneMethod = type.GetMethod("<Clone>$", BindingFlags.Public | BindingFlags.Instance);
return cloneMethod != null && cloneMethod.ReturnType == type;
return cloneMethod != null && (cloneMethod.ReturnType == type || cloneMethod.ReturnType == type.BaseType);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,26 @@ public void GetBoundConstructor_ReturnsNull_ForRecordTypeWithMultipleConstructor
Assert.Null(result);
}

[Fact]
public void GetBoundConstructor_ReturnsPrimaryConstructor_ForRecordTypeInherited()
{
// Arrange
var type = typeof(Model);

// Act
var result = DefaultBindingMetadataProvider.GetBoundConstructor(type);

// Assert
Assert.NotNull(result);
Assert.Collection(
result.GetParameters(),
p => Assert.Equal("Name", p.Name),
p => Assert.Equal("Value", p.Name));
}

public record BaseModel(int Value);
public record Model(string Name, int Value) : BaseModel(Value);

private record RecordTypeWithConformingSynthesizedConstructor
{
public RecordTypeWithConformingSynthesizedConstructor(string Name, int Age)
Expand Down