次の方法で共有


FieldInfo.IsFamilyAndAssembly プロパティ

このフィールドに、 FamilyAndAssembly レベルの参照可能範囲が設定されているかどうかを示す値を取得します。

Public ReadOnly Property IsFamilyAndAssembly As Boolean
[C#]
public bool IsFamilyAndAssembly {get;}
[C++]
public: __property bool get_IsFamilyAndAssembly();
[JScript]
public function get IsFamilyAndAssembly() : Boolean;

プロパティ値

フィールドに FamANDAssem 属性が設定されている場合は true 。それ以外の場合は false

解説

フィールドに FamilyAndAssembly レベルの参照可能範囲が設定されている場合、そのフィールドは同じアセンブリ内にある派生クラスのすべてのメンバから呼び出せますが、他の型からは呼び出せません。

IsFamilyAndAssembly プロパティは、 FieldAttributes.FamANDAssem 属性が設定されたときに設定されます。

使用例

[Visual Basic, C#, C++] クラスを作成し、クラス名、フィールドの値、フィールドの IsFamilyAndAssembly プロパティの値を表示する例を次に示します。

 
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

[C#] 
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 );
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;

public __gc class Fieldinfo_IsFamilyAndAssembly
{
public protected:
   String* myField;
public:
   Fieldinfo_IsFamilyAndAssembly()
   {
      myField = S"A protected internal field";
   }
};

int main()
{
   Fieldinfo_IsFamilyAndAssembly* myObject = new Fieldinfo_IsFamilyAndAssembly();

   // Get the Type and FieldInfo.
   Type* myType1 = __typeof(Fieldinfo_IsFamilyAndAssembly);
   FieldInfo* myFieldInfo = myType1->GetField(S"myField",
      static_cast<BindingFlags>(BindingFlags::NonPublic|BindingFlags::Instance));

   // Display the class and field name and the FamilyAndAssembly property value for the field.
   Console::Write(S"\n Name of class: {0}", myType1->FullName);
   Console::Write(S"\n Value of field: {0}", myFieldInfo->GetValue(myObject));
   Console::Write(S"\n IsFamilyAndAssembly: {0}", __box(myFieldInfo->IsFamilyAndAssembly));
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

FieldInfo クラス | FieldInfo メンバ | System.Reflection 名前空間 | FieldAttributes