Indicates whether this field has Family level visibility.
[Visual Basic] Public ReadOnly Property IsFamily As Boolean [C#] public bool IsFamily {get;} [C++] public: __property bool get_IsFamily(); [JScript] public function get IsFamily() : Boolean;
Read-only. true if the field has the Family attribute set; otherwise, false.
Boolean property indicating if the field has the Family level visibility set. It 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 being set to true.
[C#]
//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 public 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 = Type.GetType("Myfielda"); FieldInfo Myfieldinfoa = MyTypea.GetField("field", BindingFlags.NonPublic); Type MyTypeb = Type.GetType("Myfieldb"); FieldInfo Myfieldinfob = MyTypeb.GetField("field", 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}",EnumInfo.ToString( typeof(FieldAttributes),Myfieldinfoa.Attributes)); //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); FieldAttributes Myfieldattributesb = Myfieldinfob.Attributes; Console.Write("\n FieldAttributes - {0}", EnumInfo.ToString( typeof(FieldAttributes),Myfieldinfob.Attributes)); return 0; } }
This code produces the following output:
Reflection.FieldInfo
Myfielda- A private field-
IsFamily- False
FieldAttributes- Private
Myfieldb- B public field-
IsFamily- True
FieldAttributes- Family
FieldInfo Class | FieldInfo Members | System.Reflection Namespace | FieldAttributes