FieldInfo.MemberType Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets a value that indicates that this member is a field.
Assembly: mscorlib (in mscorlib.dll)
Property Value
Type: System.Reflection.MemberTypesA value that indicates that this member is a field.
| Exception | Condition |
|---|---|
| MethodAccessException | This member is invoked late-bound through mechanisms such as Type.InvokeMember. |
This property overrides MemberType. Therefore, when you examine a set of MemberInfo objects — for example, the array returned by GetMembers — the MemberType property returns MemberTypes.Field only when a given member is a field.
The following example determines whether each instance member of the Example class is a field and displays the result.
Note: |
|---|
To run this example, see Building examples that have static TextBlock controls for Windows Phone 8. |
using System; using System.Reflection; // Make a field. public class Example { private string m_field = "a private field"; public string Field { get { return m_field; } } public static void Demo(System.Windows.Controls.TextBlock outputBlock) { outputBlock.Text += "Reflection.FieldInfo\n\n"; MemberInfo[] instanceMembers = typeof(Example).GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach( MemberInfo mi in instanceMembers ) { if (mi.MemberType == MemberTypes.Field) { outputBlock.Text += String.Format("{0} is a field. <----\n", mi.Name); } else { outputBlock.Text += String.Format("{0} is not a field. \n", mi.Name); } } } } /* This example produces the following output: Reflection.FieldInfo get_Field is not a field. ToString is not a field. Equals is not a field. GetHashCode is not a field. GetType is not a field. Finalize is not a field. MemberwiseClone is not a field. .ctor is not a field. Field is not a field. m_field is a field. <---- */
Note: