简体   繁体   中英

Properties with Friend Access Modifier not being returned by Type.GetType().GetProperties

simple question can someone explain/point to how/why properties with the "friend" access modifiers are not being returned by .GetProperties method in Type.GetType()?

I've read up on the "friend" modifier here: https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/modifiers/friend but it failed to mention that.

Also is there any other "hidden" functions of the different access level modifiers? I thought all they basically do is prevent methods from being seen by other objects/classes etc...

Example:

Dim propList As New List(Of String)
For Each p as PropertyInfo In Me.GetType().GetProperties
   propList.Add(p.Name)
Next

Where "Me" is a class that contains regular "public" properties but inherits a class that contains "friend" properties.

If the code above is ran, propList will contain the names of the properties that have the "public" access modifier and will ignore the "friend" props.

You have to supply the proper BindingFlags . By default GetProperties() only shows public properties. Try something like:

// C#
GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)

' VB.NET
GetProperties(BindingFlags.Instance Or BindingFlags.Public Or BindingFlags.NonPublic)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM