Freigeben über


FieldInfo.IsAssembly-Eigenschaft

Ruft einen Wert ab, der angibt, ob für dieses Feld die Sichtbarkeitsstufe Assembly definiert ist.

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public ReadOnly Property IsAssembly As Boolean
'Usage
Dim instance As FieldInfo
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

Eigenschaftenwert

true, wenn für das Feld das Assembly-Attribut festgelegt ist, andernfalls false.

Hinweise

Wenn für ein Feld die Sichtbarkeitsstufe Assembly definiert ist, kann es von jedem Member in der Assembly aufgerufen werden, nicht jedoch von Membern außerhalb der Assembly.

Die IsAssembly-Eigenschaft ist festgelegt, wenn das FieldAttributes.Assembly-Attribut festgelegt ist. In C# können Sie das Feld als internal deklarieren, um diese Eigenschaft so festzulegen, dass der Zugriff auf dieses Feld auf dieses Projekt beschränkt ist.

Beispiel

Im folgenden Beispiel wird bestimmt, ob für die angegebenen Felder die Sichtbarkeitsstufe Assembly definiert ist, und die Ergebnisse werden angezeigt.

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic


' Make two fields.

Public Class Myfielda
    Private field As String = "A private field"

    Public Property MyField() As String
        Get
            Return MyField
        End Get
        Set(ByVal Value As String)
            If field <> Value Then
                field = Value
            End If
        End Set
    End Property
End Class 'Myfielda

Public Class Myfieldb
    Friend field As String = "B Friend field"

    Public Property MyField() As String
        Get
            Return MyField
        End Get
        Set(ByVal Value As String)
            If field <> Value Then
                field = Value
            End If
        End Set
    End Property
End Class 'Myfieldb

Public Class Myfieldinfo

    Public Shared Function Main() As Integer
        Console.WriteLine(ControlChars.Lf & "Reflection.FieldInfo")
        Dim Myfielda As New Myfielda()
        Dim Myfieldb As New Myfieldb()

        'Get the Type and FieldInfo.
        Dim MyTypea As Type = GetType(Myfielda)
        Dim Myfieldinfoa As FieldInfo = MyTypea.GetField("field", _
            BindingFlags.NonPublic Or BindingFlags.Instance)
        Dim MyTypeb As Type = GetType(Myfieldb)
        Dim Myfieldinfob As FieldInfo = MyTypeb.GetField("field", _
            BindingFlags.NonPublic Or BindingFlags.Instance)

        'For the first field, get and display the name, field, and IsAssembly.
        Console.Write(ControlChars.Lf & "{0} - ", MyTypea.FullName)
        Console.Write("{0};", Myfieldinfoa.GetValue(Myfielda))
        Console.Write(" IsAssembly = {0}; ", Myfieldinfoa.IsAssembly)
        If Myfieldinfoa.IsAssembly Then
            Console.Write("Field has limited accessibility")
        End If
        'For the second field, get and display the name, field, and IsAssembly.
        Console.Write(ControlChars.Lf & "{0} - ", MyTypeb.FullName)
        Console.Write("{0}; ", Myfieldinfob.GetValue(Myfieldb))
        Console.Write(" IsAssembly = {0}; ", Myfieldinfob.IsAssembly)
        If Myfieldinfob.IsAssembly Then
            Console.Write("Field has limited accessibility")
        End If
        Return 0
    End Function 'Main
End Class 'Myfieldinfo
//Make two fields.
public class Myfielda
{
   private string field = "A private field";
   public string Field{
      get{return field;}
      set{if(field!=value){field=value;}}
   }
}

public class Myfieldb
{
   internal string field = "B internal field";
   public string Field{
      get{return field;}
      set{if(field!=value){field=value;}}
   }
}

public class Myfieldinfo
{
   public static int Main()
   {
      Console.WriteLine("\nReflection.FieldInfo");
      Myfielda Myfielda = new Myfielda();
      Myfieldb Myfieldb = new Myfieldb();
 
      //Get the Type and FieldInfo.
      Type MyTypea = typeof(Myfielda);
      FieldInfo Myfieldinfoa = MyTypea.GetField("field", 
          BindingFlags.NonPublic|BindingFlags.Instance);
      Type MyTypeb = typeof(Myfieldb);
      FieldInfo Myfieldinfob = MyTypeb.GetField("field", 
          BindingFlags.NonPublic|BindingFlags.Instance);
 
      //For the first field, get and display the name, field, and IsAssembly.
      Console.Write("\n{0} - ", MyTypea.FullName);
      Console.Write("{0};", Myfieldinfoa.GetValue(Myfielda));
      Console.Write(" IsAssembly = {0}; ", Myfieldinfoa.IsAssembly );
      if (Myfieldinfoa.IsAssembly)
         Console.Write("Field has limited accessibility");
 
      //For the second field, get and display the name, field, and IsAssembly.

      Console.Write("\n{0} - ", MyTypeb.FullName);
      Console.Write("{0}; ", Myfieldinfob.GetValue(Myfieldb));
      Console.Write(" IsAssembly = {0}; ", Myfieldinfob.IsAssembly );
      if (Myfieldinfob.IsAssembly)
         Console.Write("Field has limited accessibility");
 
      return 0;
   }
}
//Make two fields.
public ref class Myfielda
{
private:
   String^ field;

public:
   Myfielda()
      : field( "A private field" )
   {}


   property String^ Field 
   {
      String^ get()
      {
         return field;
      }

      void set( String^ value )
      {
         if ( field != value )
         {
            field = value;
         }
      }

   }

};

public ref class Myfieldb
{
public private:
   String^ field;

public:
   Myfieldb()
      : field( "B public field" )
   {}


   property String^ Field 
   {
      String^ get()
      {
         return field;
      }

      void set( String^ value )
      {
         if ( field != value )
         {
            field = value;
         }
      }

   }

};

int main()
{
   Console::WriteLine( "\nReflection.FieldInfo" );
   Myfielda^ myfielda = gcnew Myfielda;
   Myfieldb^ myfieldb = gcnew Myfieldb;
   
   //Get the Type and FieldInfo.
   Type^ MyTypea = Type::GetType( "Myfielda" );
   FieldInfo^ Myfieldinfoa = MyTypea->GetField( "field", static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance) );
   Type^ MyTypeb = Type::GetType( "Myfieldb" );
   FieldInfo^ Myfieldinfob = MyTypeb->GetField( "field", static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance) );
   
   //For the first field, get and display the name, field, and IsAssembly.
   Console::Write( "\n{0} - ", MyTypea->FullName );
   Console::Write( "{0};", Myfieldinfoa->GetValue( myfielda ) );
   Console::Write( " IsAssembly = {0}; ", Myfieldinfoa->IsAssembly );
   if ( Myfieldinfoa->IsAssembly )
      Console::Write( "Field has limited accessibility" );

   
   //For the second field, get and display the name, field, and IsAssembly.
   Console::Write( "\n{0} - ", MyTypeb->FullName );
   Console::Write( "{0}; ", Myfieldinfob->GetValue( myfieldb ) );
   Console::Write( " IsAssembly = {0}; ", Myfieldinfob->IsAssembly );
   if ( Myfieldinfob->IsAssembly )
      Console::Write( "Field has limited accessibility" );

   return 0;
}
//Make two fields.
public class MyFieldA
{
    private String field = "A private field";

    /** @property 
     */
    public String get_Field()
    {
        return field;
    } //get_Field

    /** @property 
     */
    public void set_Field(String value)
    {
        if (field != value) {
            field = value;
        }
    } //set_Field
} //MyFieldA

public class MyFieldB
{
    String field = "B public field";

    /** @property 
     */
    public String get_Field() 
    {
        return field;
    } //get_Field

    /** @property 
     */
    public void set_Field(String value)
    {
        if (field != value) {
            field = value;
        }
    } //set_Field
} //MyFieldB

public class MyFieldInfo
{
    public static void main(String[] args)
    {
        Console.WriteLine("\nReflection.FieldInfo");
        MyFieldA myFieldA = new MyFieldA();
        MyFieldB myFieldB = new MyFieldB();

        //Get the Type and FieldInfo.
        Type myTypeA = Type.GetType("MyFieldA");
        FieldInfo myFieldInfoA = myTypeA.GetField("field", 
            BindingFlags.NonPublic | BindingFlags.Instance);
        Type myTypeB = Type.GetType("MyFieldB");
        FieldInfo myFieldInfoB = myTypeB.GetField("field", 
            BindingFlags.NonPublic | BindingFlags.Instance);

        //For the first field, get and display the name, field, and IsAssembly.
        Console.Write("\n{0} - ", myTypeA.get_FullName());
        Console.Write("{0};", myFieldInfoA.GetValue(myFieldA));
        Console.Write(" IsAssembly = {0}; ", 
            (System.Boolean)myFieldInfoA.get_IsAssembly());
        if (myFieldInfoA.get_IsAssembly()) {
            Console.Write("Field has limited accessibility");
        }

        //For the second field, get and display the name, field, and IsAssembly.
        Console.Write("\n{0} - ", myTypeB.get_FullName());
        Console.Write("{0}; ", myFieldInfoB.GetValue(myFieldB));
        Console.Write(" IsAssembly = {0}; ", 
            (System.Boolean)myFieldInfoB.get_IsAssembly());
        if (myFieldInfoB.get_IsAssembly()) {
            Console.Write("Field has limited accessibility");
        }

        return;
    } //main
} //MyFieldInfo
//Make two fields.
public class Myfielda
{
   private var field : String = "A private field";
   public function get Field() : String {
       return field;
   }
   public function set Field(value : String) {    
       if (field!=value) field=value;
   }
}

public class Myfieldb
{
   internal var field : String = "B public field";
   public function get Field() : String {
       return field;
   }
   public function set Field(value : String) {    
      if (field!=value) field=value;
   }
}

public class Myfieldinfo
{
   public static function Main() : void
   {
      Console.WriteLine("\nReflection.FieldInfo");
      var myfielda : Myfielda = new Myfielda();
      var myfieldb : Myfieldb = new Myfieldb();
 
      //Get the Type and FieldInfo.
      var MyTypea : Type = Type.GetType("Myfielda");
      var Myfieldinfoa : FieldInfo = MyTypea.GetField("field", BindingFlags.Instance|BindingFlags.NonPublic);
      var MyTypeb : Type = Type.GetType("Myfieldb");
      var Myfieldinfob : FieldInfo = MyTypeb.GetField("field", BindingFlags.Instance|BindingFlags.NonPublic);
 
      //For the first field, get and display the name, field, and IsAssembly.
      Console.Write("\n{0} - ", MyTypea.FullName);
      Console.Write("{0};", Myfieldinfoa.GetValue(myfielda));
      Console.Write(" IsAssembly = {0}; ", Myfieldinfoa.IsAssembly );
      if (Myfieldinfoa.IsAssembly)
         Console.Write("Field has limited accessibility");
 
      //For the second field, get and display the name, field, and IsAssembly.

      Console.Write("\n{0} - ", MyTypeb.FullName);
      Console.Write("{0}; ", Myfieldinfob.GetValue(myfieldb));
      Console.Write(" IsAssembly = {0}; ", Myfieldinfob.IsAssembly );
      if (Myfieldinfob.IsAssembly)
         Console.Write("Field has limited accessibility");
   }
}
Myfieldinfo.Main();

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

FieldInfo-Klasse
FieldInfo-Member
System.Reflection-Namespace
FieldAttributes-Enumeration