Standing by OO principles we would have to say "Private memebers are only visible to to the class in which it is defined"
This is the MSDN Defintion for the C# private keyword
"The private keyword is a member access modifier. Private access is the least permissive access level. Private members are accessible only within the body of the class or the struct in which they are declared.
Nested types in the same body can also access those private members.
It is a compile-time error to reference a private member outside the class or the struct in which it is declared."
The whole idea of Private access modifier being only a language construct and not an runtime principle is quite interesting.It brings up one of the core concepts of accessmodifiers only down to the degree of language compilation and enforcing them during runtime still takes a back seat.
The whole fundamental of .NET is the CLR and if we can me an excution of a private method at runtime, would this defeat the the purpose of making something private? To lay it out, this is what I am trying to ask.
public class A
private static void YouCantCallMe()
Console.WriteLine("I got called.");
static void Main(string args)
Type t = typeof(A);
t.InvokeMember("YouCantCallMe", BindingFlags.InvokeMethod |
BindingFlags.Static | BindingFlags.NonPublic, null, null, null);
The runtime with the help of reflection helps you get around one of the principles of OO which prohibits visibility of private memebers outside the current body. Personally i find it pretty cool that i can do stuff like this with reflection.
Any thoughts on this ?