Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are private members included in TypeInfo Declared properties?

Does the new TypeInfo class include private members by default in its "DeclaredXXX" properties?

like image 326
Alwyn Avatar asked Dec 26 '22 08:12

Alwyn


2 Answers

It returns both private and public members. However only ones that are declared at that level, any inherited members etc. will not be returned.

like image 108
Alwyn Avatar answered Feb 15 '23 23:02

Alwyn


If it is a Property and not a Field it will show private members in DeclaredProperties

public class Test
{
    private string test; // will not be in DeclaredProperties
    private string test2 { get; set; } // will be in DeclaredProperties
    public int test3{ get; set; }  // will be in DeclaredProperties
}

var result = typeof(Test).GetTypeInfo().DeclaredProperties;
like image 42
sa_ddam213 Avatar answered Feb 15 '23 22:02

sa_ddam213