_FieldInfo.IsFamilyOrAssemblyとは? わかりやすく解説

FieldInfo.IsFamilyOrAssembly プロパティ

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

名前空間: System.Reflection
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

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

プロパティ
フィールドFamORAssem 属性設定されている場合trueそれ以外場合false

解説解説

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

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

使用例使用例

2 つフィールド作成する例を次に示します2 番目のフィールドである Myfieldb は、最初フィールド Myfielda から派生してます。Myfielda.field は protected internal (Visual Basic の場合Friend Protected) であるため、Myfieldb.field を派生できます。Myfielda.field がプライベート フィールド場合は、Myfieldb.field を派生できません。

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();
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

_FieldInfo.IsFamilyOrAssembly プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

COM オブジェクトに、IsFamilyOrAssembly プロパティへのバージョン依存しないアクセス用意されています。

このプロパティは、CLS準拠していません。  

名前空間: System.Runtime.InteropServices
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

ReadOnly Property IsFamilyOrAssembly As
 Boolean
Dim instance As _FieldInfo
Dim value As Boolean

value = instance.IsFamilyOrAssembly
bool IsFamilyOrAssembly { get; }
property bool IsFamilyOrAssembly {
    bool get ();
}
/** @property */
boolean get_IsFamilyOrAssembly ()
function get IsFamilyOrAssembly () : boolean

プロパティ
フィールドFamORAssem 属性設定されている場合trueそれ以外場合false

解説解説

このプロパティは、アンマネージ コードからマネージ クラスアクセスするためのプロパティであるため、マネージ コードからは呼び出さないください

IsFamilyOrAssembly プロパティは、このフィールドFamilyOrAssembly レベル参照範囲設定されているかどうかを示す値を取得します

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
_FieldInfo インターフェイス
_FieldInfo メンバ
System.Runtime.InteropServices 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

_FieldInfo.IsFamilyOrAssemblyのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



_FieldInfo.IsFamilyOrAssemblyのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS