Object - GetFieldValue

A T extension method that gets a field value (Public | NonPublic | Instance | Static)

Try it

public static void Main()
{
	var obj = new FieldModel<int>()
	{
		PublicField = 3
	};
	
	//C# Extension Method: Object - GetFieldValue
	Console.WriteLine(obj.GetFieldValue("PublicField"));
	
	obj.PublicField = 5;
	
	//C# Extension Method: Object - GetFieldValue
	Console.WriteLine(obj.GetFieldValue("PublicField"));
	
}

public class FieldModel<T>
{
	public const int ConstField = 1;
    public static int StaticField;
    public readonly int ReadOnlyField = 1;
    public volatile int VolatileField = 1;
    public event EventHandler EventField;
    internal int InternalField;
    protected internal int ProtectedInternalField;
    private int PrivateField;
    protected int ProtectedField;
    public int PublicField;
    public T GenericField;
}

View Source
using System;
using System.Reflection;

public static partial class Extensions
{
    /// <summary>
    ///     A T extension method that gets a field value (Public | NonPublic | Instance | Static)
    /// </summary>
    /// <typeparam name="T">Generic type parameter.</typeparam>
    /// <param name="this">The @this to act on.</param>
    /// <param name="fieldName">Name of the field.</param>
    /// <returns>The field value.</returns>
    public static object GetFieldValue<T>(this T @this, string fieldName)
    {
        Type type = @this.GetType();
        FieldInfo field = type.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

        return field.GetValue(@this);
    }
}