Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -755,19 +755,7 @@ private static bool IsArrayCompatibleReadOnlyInterface(Type type)
private static List<PropertyInfo> GetAllProperties(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
Type type)
{
var allProperties = new List<PropertyInfo>();

Type? baseType = type;
do
{
allProperties.AddRange(baseType!.GetProperties(DeclaredOnlyLookup));
baseType = baseType.BaseType;
}
while (baseType != typeof(object));

return allProperties;
}
=> type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static).ToList();

[RequiresUnreferencedCode(PropertyTrimmingWarningMessage)]
private static object? BindParameter(ParameterInfo parameter, Type type, IConfiguration config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,21 @@ public void CanBindNullableNestedStructProperties()
Assert.True(bound.NullableNestedStruct.Value.DeeplyNested.Boolean);
}

[Fact]
public void CanBindVirtualPropertiesWithoutDuplicates()
{
ConfigurationBuilder configurationBuilder = new();
configurationBuilder.AddInMemoryCollection(new Dictionary<string, string>
{
{ "Test:0", "1" }
});
IConfiguration config = configurationBuilder.Build();

var test = new ClassOverridingVirtualProperty();
config.Bind(test);
Assert.Equal("1", Assert.Single(test.Test));
}


private interface ISomeInterface
{
Expand Down Expand Up @@ -1827,5 +1842,15 @@ public struct DeeplyNested
public bool Boolean { get; set; }
}
}

public class BaseClassWithVirtualProperty
{
public virtual string[] Test { get; set; } = System.Array.Empty<string>();
}

public class ClassOverridingVirtualProperty : BaseClassWithVirtualProperty
{
public override string[] Test { get => base.Test; set => base.Test = value; }
}
}
}