Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThatArePublicOrInternal property in PropertyInfoSelector.cs selects only the properties with get accessor #2062

Closed
94sedighi opened this issue Dec 6, 2022 · 2 comments · Fixed by #2082
Assignees

Comments

@94sedighi
Copy link
Contributor

94sedighi commented Dec 6, 2022

Description

ThatArePublicOrInternal property in PropertyInfoSelector.cs only selects the public or internal properties that have get accessor

Complete minimal example reproducing the issue

When selecting the public or internal properties of a type, it selects only the ones with get accessors. If a property has only set accessor it will not be selected.

E.g.

public class TestClassForPropertyInfoSelector{

    private static string myPrivateStaticStringField;

    public static string PublicStaticStringProperty { set => myPrivateStaticStringField = value; }

    public static string InternalStaticStringProperty { get; set; }
}


// Arrange
Type type = typeof(TestClassForPropertyInfoSelector);

// Act
IEnumerable<PropertyInfo> properties = type.Properties().ThatArePublicOrInternal.ToArray();

// Assert
properties.Should().HaveCount(2);

Expected behavior:

The test should pass because one property is internal and the other one is public and both should be selected

Actual behavior:

The test fails with following message:
Expected properties to contain 2 item(s), but found 1: {InternalStaticStringProperty}.

Additional Information

Using Visual Studio 2022

@dennisdoomen
Copy link
Member

dennisdoomen commented Dec 26, 2022

Although I loathe a property that doesn't have a getter, it is a bug indeed.

@Ruijin92
Copy link
Contributor

Ruijin92 commented Jan 2, 2023

I will fix this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants