MethodBase.IsPublic 属性
获取一个值,该值指示这是否是一个公共方法。
**命名空间:**System.Reflection
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public ReadOnly Property IsPublic As Boolean
用法
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
属性值
如果此方法是公共的,则为 true;否则为 false。
备注
若要获取 MethodBase,请首先获取类型。从类型获取方法。从方法获取 MethodBase。如果 MethodBase 或构造函数不是公共的,则它受到保护而且无法容易地进行访问。若要访问非公共方法,请在 GetMethod 中将 BindingFlags 屏蔽设置为 NonPublic。
示例
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
*/
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
MethodBase 类
MethodBase 成员
System.Reflection 命名空间
Boolean
BindingFlags 枚举