Indicates whether this field has Assembly level visibility.
[Visual Basic] Public ReadOnly Property IsAssembly As Boolean [C#] public bool IsAssembly {get;} [C++] public: __property bool get_IsAssembly(); [JScript] public function get IsAssembly() : Boolean;
Read-only. true if the field has the Assembly attribute set; otherwise, false.
If a field has Assembly level visibility, it can be called from any member within that assembly, but none outside of it.
The IsAssembly property is set when the FieldAttributes.Assembly attribute is set. Declaring the field internal, sets these properties. Declaring the field internal limits the access of this field to this project.
[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 { internal 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 IsAssembly Console.Write("\n{0} - ", MyTypea.FullName); Console.Write("{0};", Myfieldinfoa.GetValue(Myfielda)); Console.Write(" IsAssembly = {0}; ", Myfieldinfoa.IsAssembly ); if (Myfieldinfoa.IsAssembly ) Console.Write("Field has limited accessability"); //For the second field; //Get and Display the Name, field, and IsAssembly Console.Write("\n{0} - ", MyTypeb.FullName); Console.Write("{0}; ", Myfieldinfob.GetValue(Myfieldb)); Console.Write(" IsAssembly = {0}; ", Myfieldinfob.IsAssembly ); if (Myfieldinfob.IsAssembly ) Console.Write("Field has limited accessability"); return 0; } }
This code produces the following output:
Reflection.FieldInfo
Myfielda- A private field; IsAssembly = False;
Myfieldb- B public field; IsAssembly = True; Field has limited accessibility
FieldInfo Class | FieldInfo Members | System.Reflection Namespace | FieldAttributes