How do the System.Reflection.BindingFlags Public, NonPublic, and Instance correspond to the C# access modifiers?
Is the following correspondence table correct?
+-------------+--------+---------+-----------+----------+--------------------+
| BindingFlag | Public | Private | Protected | Internal | Protected Internal |
+-------------+--------+---------+-----------+----------+--------------------+
| Instance | No | No | No | Yes | Yes |
| NonPublic | No | Yes | Yes | No | No |
| Public | Yes | No | No | No | No |
| * | Yes | Yes | Yes | Yes | Yes |
+-------------+--------+---------+-----------+----------+--------------------+
* Instance | NonPublic | Public
Is there a way to make sense of this? For example, if Instance corresponds to Internal, why isn't it just called Internal?
This binding flag is used for methods with parameters that have default values and methods with variable arguments (varargs). This flag should only be used with InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]).
BindingFlags values are used to control binding in methods in classes that find and invoke, create, get, and set members and types.
Your table is not 100% correct.
Instance means that this is an "instance method" which means non-static. If you want to get non-static methods, then you use the Instance filter. If you want to get static methods then you cannot put this filter.
NonPublic means anything except for public methods. So if you use the NonPublic filter, then you will get private, protected, internal and protected internal methods.
Public means just public methods, and no other methods.
Your table should look like that:
+-------------+--------+---------+-----------+----------+--------------------+
| BindingFlag | Public | Private | Protected | Internal | Protected Internal |
+-------------+--------+---------+-----------+----------+--------------------+
| NonPublic | No | Yes | Yes | Yes | Yes |
| Public | Yes | No | No | No | No |
+-------------+--------+---------+-----------+----------+--------------------+
Putting "Instance" filter in this table doesn't make sense, as Instance does not deal with method's access level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With