MethodBase.IsPublic 属性   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个值,该值指示这是否是一个公共方法。
public:
 property bool IsPublic { bool get(); };public bool IsPublic { get; }member this.IsPublic : boolPublic ReadOnly Property IsPublic As Boolean属性值
如果此方法是公共的,则为 true;否则为 false。
实现
示例
下面的示例使用 IsPublic 属性显示一条消息,指示指定的方法是否为公共方法。
class methodbase
{
   public static int Main(string[] args)
   {
      Console.WriteLine("\nReflection.MethodBase");
      //Get the MethodBase of a method.
      //Get the type
      Type MyType = Type.GetType("System.MulticastDelegate");
      //Get and display the method
      MethodBase Mymethodbase =
         MyType.GetMethod("RemoveImpl",BindingFlags.NonPublic);
      Console.Write("\nMymethodbase = " + Mymethodbase);
      bool Myispublic = Mymethodbase.IsPublic;
      if (Myispublic)
         Console.Write ("\nMymethodbase is a public method");
      else
         Console.Write ("\nMymethodbase is not a public method");
      return 0;
   }
}
/*
Produces the following output
Reflection.MethodBase
Mymethodbase = System.Delegate RemoveImpl (System.Delegate)
Mymethodbase is not a public method
*/
Class methodbase1
    
    Public Shared Function Main() As Integer
    
        Console.WriteLine(ControlChars.Cr + "Reflection.MethodBase")
        
        'Get the MethodBase of a method.
        
        'Get the type
        Dim MyType As Type = Type.GetType("System.MulticastDelegate")
        
        'Get and display the method
        Dim Mymethodbase As MethodBase = _
           MyType.GetMethod("RemoveImpl", BindingFlags.NonPublic)
        
        Console.Write(ControlChars.Cr _
           + "Mymethodbase = " + Mymethodbase.ToString())
        
        Dim Myispublic As Boolean = Mymethodbase.IsPublic
        If Myispublic Then
            Console.Write(ControlChars.Cr _
               + "Mymethodbase is a public method")
        Else
            Console.Write(ControlChars.Cr _
               + "Mymethodbase is not a public method")
        End If 
        Return 0
    End Function
End Class
' Produces the following output
' 
' Reflection.MethodBase
' Mymethodbase = System.Delegate RemoveImpl (System.Delegate)
' Mymethodbase is not a public method
注解
若要获取 , MethodBase请先获取 类型。 从 类型中获取 方法。 从 方法中 MethodBase,获取 。 
              MethodBase如果 或 构造函数不是公共构造函数,则它将受到保护,并且无法轻松访问。 若要访问非公共方法,请在 中GetMethod将BindingFlags掩码NonPublic设置为 。