FieldInfo.IsFamilyAndAssembly 属性
获取一个值,通过该值指示此字段是否有 FamilyAndAssembly 级可见性。
**命名空间:**System.Reflection
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public ReadOnly Property IsFamilyAndAssembly As Boolean
用法
Dim instance As FieldInfo
Dim value As Boolean
value = instance.IsFamilyAndAssembly
public bool IsFamilyAndAssembly { get; }
public:
virtual property bool IsFamilyAndAssembly {
bool get () sealed;
}
/** @property */
public final boolean get_IsFamilyAndAssembly ()
public final function get IsFamilyAndAssembly () : boolean
属性值
如果字段设置了 FamANDAssem 属性 (Attribute),则为 true;否则为 false。
备注
如果字段具有 FamilyAndAssembly 级可见性,则可以从同一程序集的派生类中的任何成员调用此字段,但不可以从任何其他类型调用此字段。
设置 FieldAttributes.FamANDAssem 属性 (Attribute) 时设置 IsFamilyAndAssembly 属性 (Property)。
示例
下面的示例创建一个类,并显示该类的名称、字段名以及字段的 IsFamilyAndAssembly 属性 (Property) 值。
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class Fieldinfo_IsFamilyAndAssembly
Protected Friend myField As String = "A protected internal field"
Public Shared Sub Main()
Dim myObject As New Fieldinfo_IsFamilyAndAssembly()
' Get the Type and FieldInfo.
Dim myType1 As Type = GetType(Fieldinfo_IsFamilyAndAssembly)
Dim myFieldInfo As FieldInfo = myType1.GetField("myField", BindingFlags.NonPublic Or BindingFlags.Instance)
' Display the class and field name and the FamilyAndAssembly property value for the field.
Console.Write(ControlChars.Lf & " Name of class: {0}", myType1.FullName)
Console.Write(ControlChars.Lf & " Value of field: {0}", myFieldInfo.GetValue(myObject))
Console.Write(ControlChars.Lf & " IsFamilyAndAssembly: {0}", myFieldInfo.IsFamilyAndAssembly)
End Sub 'Main
End Class 'Fieldinfo_IsFamilyAndAssembly
using System;
using System.Reflection;
public class Fieldinfo_IsFamilyAndAssembly
{
protected internal string myField = "A protected internal field";
public static void Main()
{
Fieldinfo_IsFamilyAndAssembly myObject = new
Fieldinfo_IsFamilyAndAssembly();
// Get the Type and FieldInfo.
Type myType1 = typeof(Fieldinfo_IsFamilyAndAssembly);
FieldInfo myFieldInfo = myType1.GetField("myField",
BindingFlags.NonPublic|BindingFlags.Instance);
// Display the class and field name and the FamilyAndAssembly property value for the field.
Console.Write("\n Name of class: {0}", myType1.FullName);
Console.Write("\n Value of field: {0}", myFieldInfo.GetValue(myObject));
Console.Write("\n IsFamilyAndAssembly: {0}",
myFieldInfo.IsFamilyAndAssembly );
}
}
using namespace System;
using namespace System::Reflection;
public ref class Fieldinfo_IsFamilyAndAssembly
{
public protected:
String^ myField;
public:
Fieldinfo_IsFamilyAndAssembly()
{
myField = "A protected internal field";
}
};
int main()
{
Fieldinfo_IsFamilyAndAssembly^ myObject = gcnew Fieldinfo_IsFamilyAndAssembly;
// Get the Type and FieldInfo.
Type^ myType1 = Fieldinfo_IsFamilyAndAssembly::typeid;
FieldInfo^ myFieldInfo = myType1->GetField( "myField", static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance) );
// Display the class and field name and the FamilyAndAssembly property value for the field.
Console::Write( "\n Name of class: {0}", myType1->FullName );
Console::Write( "\n Value of field: {0}", myFieldInfo->GetValue( myObject ) );
Console::Write( "\n IsFamilyAndAssembly: {0}", myFieldInfo->IsFamilyAndAssembly );
}
import System.*;
import System.Reflection.*;
public class FieldinfoIsFamilyAndAssembly
{
protected String myField = "A protected internal field";
public static void main(String[] args)
{
FieldinfoIsFamilyAndAssembly myObject =
new FieldinfoIsFamilyAndAssembly();
// Get the Type and FieldInfo.
Type myType1 = FieldinfoIsFamilyAndAssembly.class.ToType();
FieldInfo myFieldInfo = myType1.GetField("myField",
BindingFlags.NonPublic | BindingFlags.Instance);
// Display the class and field name and the FamilyAndAssembly property
// value for the field.
Console.Write("\n Name of class: {0}", myType1.get_FullName());
Console.Write("\n Value of field: {0}",
myFieldInfo.GetValue(myObject));
Console.Write("\n IsFamilyAndAssembly: {0}",
(System.Boolean)myFieldInfo.get_IsFamilyAndAssembly());
} //main
} //FieldinfoIsFamilyAndAssembly
平台
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
请参见
参考
FieldInfo 类
FieldInfo 成员
System.Reflection 命名空间
FieldAttributes 枚举