Access Modifiers

Member nodes such as data types, fields, properties, methods, and events have access modifiers associated with them. These define the level of object-oriented encapsulation implemented by the member. The introspection API provides properties to determine which access modifier is applied. You are familiar with these; however each .NET language has slightly different names for the modifiers. The following table shows you how to convert between the language-specific modifiers and the properties provided by Member nodes.

Table 1. Access Modifiers

Introspection PropertyC#VB.NETC++/CLI
IsPublicpublicPublicpublic
IsFamilyOrAssemblyprotected internalProtected Friendpublic protected
IsFamilyprotectedProtectedprotected
IsFamilyAndAssemblyn/an/aprotected private
IsAssemblyinternalFriendinternal
IsPrivateprivatePrivateprivate

[Important]Important

On any member node, exactly one of these properties is true and all of the others are false. For example, to determine if a member is visible in inherited types, you need to check using the expression (node.IsFamilyOrAssembly || node.IsFamily || node.IsFamilyOrAssembly) in C# or (node.IsFamilyOrAssembly OrElse node.IsFamily OrElse node.IsFamilyOrAssembly) in VB.NET. It is not sufficient to check just for IsFamily.

Sometimes, instead of using the above properties, you only care whether or not the member is ultimately exposed for use outside the assembly. You may want to enforce stricter FxCop rules for the members that constitute your published API versus members that are just internal implementation details. Introspection considers such members "externally visible" and provides the IsVisibleOutsideAssembly property. For example, a public method in a public class is considered externally visible as is a protected method in a public class. However, a public method in a private class is not externally visible.