MethodBase.IsPublic 속성

정의

이 메서드가 public 메서드인지 여부를 나타내는 값을 가져옵니다.Gets a value indicating whether this is a public method.

public:
 property bool IsPublic { bool get(); };
public bool IsPublic { get; }
member this.IsPublic : bool
Public ReadOnly Property IsPublic As Boolean

속성 값

이 메서드가 public 메서드이면 true이고, 그렇지 않으면 false입니다.true if this method is public; otherwise, false.

구현

예제

다음 예제에서는 IsPublic 속성을 사용 하 여 지정 된 메서드가 public 인지 여부를 나타내는 메시지를 표시 합니다.The following example uses the IsPublic property to display a message that indicates whether the specified method is public.

int main()
{
   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", static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance) );
   Console::Write( "\nMymethodbase = {0}", 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 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를 가져오려면 먼저 형식을 가져옵니다.To get the MethodBase, first get the type. 형식에서 메서드를 가져옵니다.From the type, get the method. 메서드에서 MethodBase가져옵니다.From the method, get the MethodBase. MethodBase 또는 생성자가 public이 아닌 경우 보호 되며 쉽게 액세스할 수 없습니다.If the MethodBase or constructor is other than public, it is protected and cannot be readily accessed. Public이 아닌 메서드에 액세스 하려면 BindingFlags 마스크를 GetMethod에서 NonPublic로 설정 합니다.To access a non-public method, set the BindingFlags mask to NonPublic in GetMethod.

적용 대상

추가 정보