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.
Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Syntax
Public Overrides ReadOnly Property MemberType As MemberTypes
public override MemberTypes MemberType { get; }
Property Value
Type: System.Reflection..::.MemberTypes
A value that indicates that this member is a field.
Exceptions
Exception | Condition |
---|---|
MethodAccessException | This member is invoked late-bound through mechanisms such as Type..::.InvokeMember. |
Remarks
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.
Examples
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.
Imports System.Reflection
' Make a field.
Public Class Example
Private m_field As String = "a private field"
Public ReadOnly Property Field() As String
Get
Return m_field
End Get
End Property
Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
outputBlock.Text &= "Reflection.FieldInfo" & vbCrLf & vbCrLf
Dim instanceMembers() As MemberInfo = _
GetType(Example).GetMembers(BindingFlags.Public Or BindingFlags.NonPublic Or _
BindingFlags.Instance)
For Each mi As MemberInfo In instanceMembers
If mi.MemberType = MemberTypes.Field Then
outputBlock.Text += String.Format("{0} is a field. <----" & vbLf, mi.Name)
Else
outputBlock.Text += String.Format("{0} is not a field. " & vbLf, mi.Name)
End If
Next mi
End Sub
End Class
' 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. <----
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. <----
*/
Version Information
Windows Phone OS
Supported in: 8.1, 8.0, 7.1, 7.0
Platforms
Windows Phone