This documentation is archived and is not being maintained.

FieldInfo.IsFamily Property

Gets a value indicating whether this field has Family level visibility.

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

public bool IsFamily { get; }
/** @property */
public final boolean get_IsFamily ()

public final function get IsFamily () : boolean

Property Value

true if the field has the Family attribute set; otherwise, false.

This property can be called from any member in a derived class, but not from any other type.

To get the IsFamily property, first get the class Type. From the Type, get the FieldInfo. From the FieldInfo, get the IsFamily value.

The IsFamily property is set when the FieldAttributes.Family attribute is set.

In the following example, two properties are created. The first property has a private string field and the second property has a protected string field, resulting in the IsFamily property being set to true.

using System;
using System.Reflection;

//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
{
    protected string field = "B protected 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 IsFamily.
        Console.Write("\n{0} - ", MyTypea.FullName);
        Console.Write("{0} - ", Myfieldinfoa.GetValue(Myfielda));
        Console.Write("\n  IsFamily - {0}", Myfieldinfoa.IsFamily);
        Console.Write("\n  FieldAttributes - {0}",
            Myfieldinfoa.Attributes.ToString());
  
        // For the second field, get and Display the Name, field, and IsFamily.
        Console.WriteLine();
        Console.Write("\n{0} - ", MyTypeb.FullName);
        Console.Write("{0} - ", Myfieldinfob.GetValue(Myfieldb));
        Console.Write("\n  IsFamily - {0}", Myfieldinfob.IsFamily);
        FieldAttributes Myfieldattributesb = Myfieldinfob.Attributes;
        Console.Write("\n  FieldAttributes - {0}",
            Myfieldinfob.Attributes.ToString());
  
        return 0;
    }
}

import System.*;
import System.Reflection.*;

//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
{
    protected 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 IsFamily.
        Console.Write("\n{0} - ", myTypeA.get_FullName());
        Console.Write("{0} - ", myFieldInfoA.GetValue(myFieldA));
        Console.Write("\n  IsFamily - {0}", 
            (System.Boolean)myFieldInfoA.get_IsFamily());
        Console.Write("\n  FieldAttributes - {0}", 
            myFieldInfoA.get_Attributes().ToString());

        // For the second field, get and Display the Name, field, and IsFamily.
        Console.WriteLine();
        Console.Write("\n{0} - ", myTypeB.get_FullName());
        Console.Write("{0} - ", myFieldInfoB.GetValue(myFieldB));
        Console.Write("\n  IsFamily - {0}",
            (System.Boolean)myFieldInfoB.get_IsFamily());
        FieldAttributes Myfieldattributesb = myFieldInfoB.get_Attributes();
        Console.Write("\n  FieldAttributes - {0}",
            myFieldInfoB.get_Attributes().ToString());

        return;
    } //main
} //MyFieldInfo

//Make two fields.
import System;
import System.Reflection;

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
{
   protected 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 IsFamily.
      Console.Write("\n{0} - ", MyTypea.FullName);
      Console.Write("{0} - ", Myfieldinfoa.GetValue(myfielda));
      Console.Write("\n  IsFamily - {0}", Myfieldinfoa.IsFamily);
      Console.Write("\n  FieldAttributes - {0}",
         Myfieldinfoa.Attributes.ToString());
 
      //For the second field, get and Display the Name, field, and IsFamily.
      Console.Write("\n{0} - ", MyTypeb.FullName);
      Console.Write("{0} - ", Myfieldinfob.GetValue(myfieldb));
      Console.Write("\n  IsFamily - {0}", Myfieldinfob.IsFamily);
      var Myfieldattributesb : FieldAttributes = Myfieldinfob.Attributes;
      Console.Write("\n  FieldAttributes - {0}",
         Myfieldinfob.Attributes.ToString());
   }
}
Myfieldinfo.Main();

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Show: