Public Shared Function GetPropertyVisiblity(ByVal pi As PropertyInfo) As Integer
Dim mSetMethod As MethodInfo
Dim mGetMethod As MethodInfo
Dim mCheck As MethodInfo
If the property is not write-only, get its "Get" method
If pi.CanRead Then mGetMethod = pi.GetGetMethod(True)
If the property is not read-only, get its "Set" method
If pi.CanWrite Then mSetMethod = pi.GetSetMethod(True)
If there is no "set" method, use the "get" method, and vice versa
If mSetMethod Is Nothing Then
mCheck = mGetMethod
ElseIf mGetMethod Is Nothing Then
mCheck = mSetMethod
Else
mCheck = mSetMethod
End If
Get the attributes of the method
Dim mAttr As MethodAttributes = mCheck.Attributes And MethodAttributes.MemberAccessMask
Check its visibility
If (mAttr And MethodAttributes.Public) = MethodAttributes.Public Then
Return 1 public
ElseIf (mAttr And MethodAttributes.Family) = MethodAttributes.Family Then
Return 2 protected
ElseIf (mAttr And MethodAttributes.Assembly) = MethodAttributes.Assembly Then
Return 3 internal
ElseIf (mAttr And MethodAttributes.Private) = MethodAttributes.Private Then
Return 4 private
End If
End Function