NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

FieldInfo.IsFamilyOrAssembly

Indicates whether this field has FamilyORAssembly level visibility.

[Visual Basic]
Public ReadOnly Property IsFamilyOrAssembly As Boolean
[C#]
public bool IsFamilyOrAssembly {get;}
[C++]
public: __property bool get_IsFamilyOrAssembly();
[JScript]
public function get IsFamilyOrAssembly() : Boolean;

Property Value

Read-only. true if the field has the FamORAssem attribute set; otherwise, false.

Remarks

If a field has FamilyORAssembly level visibility, it can be called from any member in a derived class or any member in the same assembly, but not from any other type. A derived class can access a protected member of a base class with this flag set.The IsFamilyOrAssembly property is set when the FieldAttributes.FamORAssem attribute is set.

Example [C#]

In the following example, two fields are created. The second field, Myfieldb is derived from the first, Myfielda. The Myfielda.field is protected internal, which allows Myfieldb.field to be derived. If Myfielda.field was a private field, Myfieldb.field could not be derived.

[C#]

//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 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 = 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 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 accessability");
 
      //For the second field;
      //Get and Display the Name, field 
      Console.Write("\n{0} - ", MyTypeb.FullName);
      Console.Write("{0}; ", Myfieldinfob.GetValue(Myfieldb));
 
      return 0;
   }
}

This code produces the following output:

Reflection.FieldInfo

Myfielda- A private field; IsFamilyOrAssembly = True; Field has limited accessibility

Myfieldb- A private field;

See Also

FieldInfo Class | FieldInfo Members | System.Reflection Namespace | FieldAttributes