Retrieves the Type of property reflected by this FieldInfo object. The retrieved value indicates that this member is a field.
[Visual Basic] Overridable Public ReadOnly Property MemberType As MemberTypes [C#] public MemberTypes MemberType {override get;} [C++] public: __property virtual MemberTypes get_MemberType(); [JScript] public function get MemberType() : MemberTypes;
Read-only. Returns MemberTypes.Field.
This is used when this field is being tested as generic member.
[C#]
//Make a field public class Myfield { private string field = "a private field"; public string Field{ get{return field;} } } public class Myfieldinfo { public static int Main() { Console.WriteLine ("\nReflection.FieldInfo"); Myfield Myfield = new Myfield(); //Get the Type and FieldInfo Type MyType = Type.GetType("Myfield"); FieldInfo Myfieldinfo = MyType.GetField("field", BindingFlags.NonPublic); //Get and Display the MemberType Console.Write ("\n{0}.", MyType.FullName); Console.Write ("{0} - ", Myfieldinfo.Name); Console.Write ("{0};", Myfield.Field); MemberTypes Mymembertypes = Myfieldinfo.MemberType; Console.Write(" MemberType is a {0}", EnumInfo.ToString(typeof(MemberTypes), Mymembertypes)); return 0; } }
This code produces the following output:
Reflection.FieldInfo
Myfield.field- a private field; MemberType is a Field
FieldInfo Class | FieldInfo Members | System.Reflection Namespace