FieldInfo.IsFamilyOrAssembly-Eigenschaft
Ruft einen Wert ab, der angibt, ob für dieses Feld die Sichtbarkeitsstufe FamilyOrAssembly definiert ist.
Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public ReadOnly Property IsFamilyOrAssembly As Boolean
'Usage
Dim instance As FieldInfo
Dim value As Boolean
value = instance.IsFamilyOrAssembly
public bool IsFamilyOrAssembly { get; }
public:
virtual property bool IsFamilyOrAssembly {
bool get () sealed;
}
/** @property */
public final boolean get_IsFamilyOrAssembly ()
public final function get IsFamilyOrAssembly () : boolean
Eigenschaftenwert
true, wenn für das Feld das FamORAssem-Attribut festgelegt ist, andernfalls false.
Hinweise
Wenn für ein Feld die Sichtbarkeitsstufe FamilyOrAssembly definiert ist, kann es von allen Membern einer abgeleiteten Klasse und allen Membern einer Assembly aufgerufen werden, nicht jedoch von anderen Typen.
Die IsFamilyOrAssembly-Eigenschaft ist festgelegt, wenn das FieldAttributes.FamORAssem-Attribut festgelegt ist.
Beispiel
Im folgenden Beispiel werden zwei Felder erstellt. Das zweite Feld, Myfieldb, ist vom ersten Feld, Myfielda, abgeleitet. Myfielda.field ist protected internal (Friend Protected in Visual Basic), sodass Myfieldb.field abgeleitet werden kann. Wäre Myfielda.field ein privates Feld, könnte Myfieldb.field nicht abgeleitet werden.
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
' Make two fields.
Public Class Myfielda
' Note that if the private line below is uncommented
' and the protected internal line below is commented out,
' this will not compile, because Myfielda.field is inaccessible.
' private string field = "A private field";
Protected Friend field As String = "A private field"
Public Property MyField() As String
Get
Return field
End Get
Set(ByVal Value As String)
If field <> value Then
field = value
End If
End Set
End Property
End Class 'Myfielda
' Myfieldb is derived from Myfielda.
' The protected internal string field allows
' the IsFamilyOrAssembly flag to be set and allows
' the field to be visible from a derived class.
Public Class Myfieldb
Inherits Myfielda
Public Shadows Property MyField() As String
Get
Return field
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("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
' IsFamilyOrAssembly.
Console.WriteLine("{0} - {1}", MyTypea.FullName, Myfieldinfoa.GetValue(Myfielda))
Console.WriteLine("IsFamilyOrAssembly = {0}", Myfieldinfoa.IsFamilyOrAssembly)
If Myfieldinfoa.IsFamilyOrAssembly Then
Console.WriteLine("Field has limited accessibility")
End If
' For the second field, get and display the name and field.
Console.WriteLine("{0} - {1}", MyTypeb.FullName, Myfieldinfob.GetValue(Myfieldb))
Return 0
End Function 'Main
End Class 'Myfieldinfo
using System;
using System.Reflection;
//Make two fields.
public class Myfielda
// Note that if the private line below is uncommented
// and the protected internal line below is commented out,
// this will not compile, because Myfielda.field is inaccessible.
{
// private string field = "A private field";
protected internal string field = "A private field";
public string Field
{
get{return field;}
set{if(field!=value) {field=value;}}
}
}
// Myfieldb is derived from Myfielda.
// The protected internal string field allows
// the IsFamilyOrAssembly flag to be set and allows
// the field to be visible from a derived class.
public class Myfieldb:Myfielda
{
new 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
// IsFamilyOrAssembly.
Console.WriteLine("\n{0} - ", MyTypea.FullName);
Console.WriteLine("{0};", Myfieldinfoa.GetValue(Myfielda));
Console.WriteLine("IsFamilyOrAssembly = {0};",
Myfieldinfoa.IsFamilyOrAssembly);
if (Myfieldinfoa.IsFamilyOrAssembly )
Console.WriteLine("Field has limited accessibility");
// For the second field, get and display the name and field.
Console.WriteLine("\n{0} - ", MyTypeb.FullName);
Console.WriteLine("{0}", Myfieldinfob.GetValue(Myfieldb));
return 0;
}
}
using namespace System;
using namespace System::Reflection;
//Make two fields.
// Note that if the private: line below is uncommented
// and the public protected: line below is commented out,
// this will not compile, because Myfielda.field is inaccessible.
public ref class Myfielda
{
public protected:
// 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;
}
}
}
};
// Myfieldb is derived from Myfielda.
// The protected internal string field allows
// the IsFamilyOrAssembly flag to be set and allows
// the field to be visible from a derived class.
public ref class Myfieldb: public Myfielda
{
public:
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
// IsFamilyOrAssembly.
Console::WriteLine( "\n{0} - ", MyTypea->FullName );
Console::WriteLine( "{0};", Myfieldinfoa->GetValue( myfielda ) );
Console::WriteLine( "IsFamilyOrAssembly = {0};", Myfieldinfoa->IsFamilyOrAssembly );
if ( Myfieldinfoa->IsFamilyOrAssembly )
Console::WriteLine( "Field has limited accessibility" );
// For the second field, get and display the name and field.
Console::WriteLine( "\n{0} - ", MyTypeb->FullName );
Console::WriteLine( "{0}", Myfieldinfob->GetValue( myfieldb ) );
return 0;
}
import System.*;
import System.Reflection.*;
//Make two fields.
public class MyFieldA
{
// Note that if the private line below is uncommented
// and the protected internal line below is commented out,
// this will not compile, because MyFieldA.field is inaccessible.
// private string field = "A private field";
protected 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
// MyFieldB is derived from MyFieldA.
// The protected internal string field allows
// the IsFamilyOrAssembly flag to be set and allows
// the field to be visible from a derived class.
public class MyFieldB extends MyFieldA
{
/** @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
// IsFamilyOrAssembly.
Console.WriteLine("\n{0} - ", myTypeA.get_FullName());
Console.WriteLine("{0};", myFieldInfoA.GetValue(myFieldA));
Console.WriteLine("IsFamilyOrAssembly = {0};",
(System.Boolean)myFieldInfoA.get_IsFamilyOrAssembly());
if (myFieldInfoA.get_IsFamilyOrAssembly()) {
Console.WriteLine("Field has limited accessibility");
}
// For the second field, get and display the name and field.
Console.WriteLine("\n{0} - ", myTypeB.get_FullName());
Console.WriteLine("{0}", myFieldInfoB.GetValue(myFieldB));
return;
} //main
} //MyFieldInfo
//Make two fields.
public class Myfielda
//Note that if the private line below is uncommented
//and the protected internal line below is commented out,
//this will not compile as Myfielda.field is inaccessible.
{
//private string field = "A private field";
protected internal var field : String = "A private field";
}
//Myfieldb is derived from Myfielda.
//The protected internal string field allows
//the IsFamilyOrAssembly flag to be set and allows
//the field to be visible from a derived class.
public class Myfieldb extends Myfielda
{
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.NonPublic|BindingFlags.Instance);
var MyTypeb : Type = Type.GetType("Myfieldb");
var Myfieldinfob : FieldInfo = MyTypeb.GetField("field",
BindingFlags.NonPublic|BindingFlags.Instance);
//For the first field, get and display the Name, field, and
//IsFamilyOrAssembly.
Console.Write("\n{0} - ", MyTypea.FullName);
Console.Write("{0};", Myfieldinfoa.GetValue(myfielda));
Console.Write("\n IsFamilyOrAssembly = {0};",
Myfieldinfoa.IsFamilyOrAssembly);
if (Myfieldinfoa.IsFamilyOrAssembly )
Console.Write("Field has limited accessibility");
//For the second field, get and display the name and field.
Console.Write("\n{0} - ", MyTypeb.FullName);
Console.Write("{0}; ", Myfieldinfob.GetValue(myfieldb));
}
}
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