MethodBase.IsPublic-Eigenschaft
Ruft einen Wert ab, der angibt, ob dies eine öffentliche Methode ist.
Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public ReadOnly Property IsPublic As Boolean
'Usage
Dim instance As MethodBase
Dim value As Boolean
value = instance.IsPublic
public bool IsPublic { get; }
public:
virtual property bool IsPublic {
bool get () sealed;
}
/** @property */
public final boolean get_IsPublic ()
public final function get IsPublic () : boolean
Eigenschaftenwert
true, wenn diese Methode öffentlich ist, andernfalls false.
Hinweise
Rufen Sie zuerst den Typ ab, um MethodBase abzurufen. Rufen Sie die Methode aus dem Typ ab. Rufen Sie MethodBase aus der Methode ab. Wenn MethodBase oder der Konstruktor nicht öffentlich sind, sind sie geschützt, und der Zugriff darauf ist nicht ohne weiteres möglich. Legen Sie die BindingFlags-Maske in GetMethod auf NonPublic fest, um auf eine nicht öffentliche Methode zugreifen zu können.
Beispiel
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
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
*/
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 void 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));
boolean myIsPublic = myMethodBase.get_IsPublic();
if (myIsPublic) {
Console.Write("\nmyMethodBase is a public method");
}
else {
Console.Write("\nmyMethodBase is not a public method");
}
} //main
} //Methodbase
/*
Produces the following output
Reflection.MethodBase
Mymethodbase = System.Delegate RemoveImpl (System.Delegate)
Mymethodbase is not a public method
*/
class methodbase
{
public static function Main() : void
{
Console.WriteLine("\nReflection.MethodBase");
//Get the MethodBase of a method.
//Get the type
var MyType : Type = Type.GetType("System.MulticastDelegate");
//Get and display the method
var Mymethodbase : MethodBase =
MyType.GetMethod("RemoveImpl",BindingFlags.NonPublic|BindingFlags.Instance);
Console.Write("\nMymethodbase = " + Mymethodbase);
var Myispublic : boolean = Mymethodbase.IsPublic;
if (Myispublic)
Console.Write ("\nMymethodbase is a public method");
else
Console.Write ("\nMymethodbase is not a public method");
}
}
methodbase.Main();
/*
Produces the following output
Reflection.MethodBase
Mymethodbase = System.Delegate RemoveImpl (System.Delegate)
Mymethodbase is not a public method
*/
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
MethodBase-Klasse
MethodBase-Member
System.Reflection-Namespace
Boolean
BindingFlags-Enumeration