MethodBase.IsAssembly 属性

获取一个值,该值指示此方法是否可以由同一程序集中的其他类调用。

**命名空间:**System.Reflection
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public ReadOnly Property IsAssembly As Boolean
用法
Dim instance As MethodBase
Dim value As Boolean

value = instance.IsAssembly
public bool IsAssembly { get; }
public:
virtual property bool IsAssembly {
    bool get () sealed;
}
/** @property */
public final boolean get_IsAssembly ()
public final function get IsAssembly () : boolean

属性值

如果此方法可以由同一程序集中的其他类调用,则为 true;否则为 false

备注

如果已设置,则此方法可以由同一程序集中的其他类调用。

若要获取 MethodBase,请首先获取类型。从类型获取方法。从方法获取 MethodBase。如果 MethodBase 或构造函数不是公共的,则它受到保护而且无法容易地进行访问。若要访问非公共方法,请在 GetMethod 中将 BindingFlags 屏蔽设置为 NonPublic

示例

下面的示例确定指定的方法是否可以由同一程序集中的其他类调用,并显示结果。

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Class methodbase1
    Friend Sub f()
    End Sub

    Public Shared Function Main() As Integer
        Console.WriteLine(ControlChars.CrLf + "Reflection.MethodBase")
        
        'Get the types.
        Dim MyType1 As Type = _
           Type.GetType("System.Runtime.Serialization.Formatter")
        Dim MyType2 As Type = _
           Type.GetType("methodbase1")

        ' Get and display the methods and the IsAssembly property value.
        Dim Mymethodbase1 As MethodBase = _
           MyType1.GetMethod("WriteInt32", BindingFlags.NonPublic Or BindingFlags.Instance)
        Dim Mymethodbase2 As MethodBase = _
           MyType2.GetMethod("f", BindingFlags.NonPublic Or BindingFlags.Instance)
       
        Console.Write(ControlChars.CrLf _
           + "Mymethodbase = " + Mymethodbase1.ToString())
        If Mymethodbase1.IsAssembly Then
            Console.Write(ControlChars.CrLf _
               + "Mymethodbase is an assembly method.")
        Else
            Console.Write(ControlChars.CrLf _
               + "Mymethodbase is not an assembly method.")
        End If 
        Console.Write(ControlChars.CrLf + ControlChars.CrLf _
           + "Mymethodbase = " + Mymethodbase2.ToString())
        If Mymethodbase2.IsAssembly Then
            Console.Write(ControlChars.CrLf + _
               "Mymethodbase is an assembly method.")
        Else
            Console.Write(ControlChars.CrLf + _
               "Mymethodbase is not an assembly method.")
        End If 
        Return 0
    End Function
End Class
using System;
using System.Reflection;

class methodbase
{
    internal void f() { }
    public static int Main(string[] args)
    { 
        Console.WriteLine ("\nReflection.MethodBase");
       
        // Get the MethodBase of two methods.
 
        // Get the types.
        Type MyType1 = Type.GetType("System.Runtime.Serialization.Formatter");
        Type MyType2 = Type.GetType("methodbase");
 
        // Get and display the methods and the IsAssembly property value.
        MethodBase Mymethodbase1 = 
            MyType1.GetMethod("WriteInt32",BindingFlags.NonPublic|BindingFlags.Instance);
        MethodBase Mymethodbase2 = 
            MyType2.GetMethod("f", BindingFlags.NonPublic|BindingFlags.Instance);
 
        Console.Write("\nMymethodbase = " + Mymethodbase1.ToString());
        if (Mymethodbase1.IsAssembly)
            Console.Write ("\nMymethodbase is an assembly method.");
        else
            Console.Write ("\nMymethodbase is not an assembly method.");
 
        Console.Write("\n\nMymethodbase = " + Mymethodbase2.ToString());
        if (Mymethodbase2.IsAssembly)
            Console.Write ("\nMymethodbase is an assembly method.");
        else
            Console.Write ("\nMymethodbase is not an assembly method.");
       
        return 0;
    }
}
using namespace System;
using namespace System::Reflection;
public ref class methodbase
{
public private:
   void f(){}

};

int main()
{
   Console::WriteLine( "\nReflection.MethodBase" );
   
   // Get the MethodBase of two methods.
   // Get the types.
   Type^ MyType1 = Type::GetType( "System.Runtime.Serialization.Formatter" );
   Type^ MyType2 = Type::GetType( "methodbase" );
   
   // Get and display the methods and the IsAssembly property value.
   MethodBase^ Mymethodbase1 = MyType1->GetMethod( "WriteInt32", static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance) );
   MethodBase^ Mymethodbase2 = MyType2->GetMethod( "f", static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance) );
   Console::Write( "\nMymethodbase = {0}", Mymethodbase1 );
   if ( Mymethodbase1->IsAssembly )
      Console::Write( "\nMymethodbase is an assembly method." );
   else
      Console::Write( "\nMymethodbase is not an assembly method." );

   Console::Write( "\n\nMymethodbase = {0}", Mymethodbase2 );
   if ( Mymethodbase2->IsAssembly )
      Console::Write( "\nMymethodbase is an assembly method." );
   else
      Console::Write( "\nMymethodbase is not an assembly method." );

   return 0;
}
import System.*;
import System.Reflection.*;

class Methodbase
{
    void F()
    {
    } //F

    public static void main(String[] args)
    {
        Console.WriteLine("\nReflection.MethodBase");

        // Get the MethodBase of two methods.
        // Get the types.
        Type myType1 = Type.GetType("System.Runtime.Serialization.Formatter");
        Type myType2 = Type.GetType("Methodbase");

        // Get and display the methods and the IsAssembly property value.
        MethodBase myMethodBase1 = myType1.GetMethod("WriteInt32", 
            BindingFlags.NonPublic | BindingFlags.Instance);
        MethodBase myMethodBase2 = myType2.GetMethod("F",
            BindingFlags.NonPublic | BindingFlags.Instance|
            BindingFlags.Public);
        Console.Write(("\nmyMethodBase = " + myMethodBase1.ToString()));
        if ( myMethodBase1.get_IsAssembly()  ) {
            Console.Write("\nmyMethodBase is an assembly method.");
        }
        else {
            Console.Write("\nmyMethodBase is not an assembly method.");
        } 
        Console.Write(("\n\nmyMethodBase = " + myMethodBase2.ToString()));
        if ( myMethodBase2.get_IsAssembly()  ) {
            Console.Write("\nmyMethodBase is an assembly method.");
        }
        else {
            Console.Write("\nmyMethodBase is not an assembly method.");
        } 

    } //main
} //methodbase

平台

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 命名空间
FieldAttributes 枚举
Boolean
BindingFlags 枚举