MemberInfo - GetDeclaraction

A MemberInfo extension method that gets a declaraction.

Try it

public static void Main()
    MemberInfo [] members = typeof(FieldModel<int>).GetMember("P*", BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

    foreach (var member in members)
		//C# Extension Method: MemberInfo - GetDeclaraction

public class FieldModel<T>
    #region Modifier

    public const int ConstField = 1;
    public static int StaticField;
    public readonly int ReadOnlyField = 1;
    public volatile int VolatileField = 1;
    public event EventHandler EventField;


    #region Visibility

    internal int InternalField;
    protected internal int ProtectedInternalField;
    private int PrivateField;
    protected int ProtectedField;
    public int PublicField;


    #region Generic

    public T GenericField;


View Source
using System;
using System.Reflection;

public static partial class Extensions
    /// <summary>A MemberInfo extension method that gets a declaraction.</summary>
    /// <param name="this">The @this to act on.</param>
    /// <returns>The declaraction.</returns>
    public static string GetDeclaraction(this MemberInfo @this)
        switch (@this.MemberType)
            case MemberTypes.Field:
                return ((FieldInfo) @this).GetDeclaraction();
            case MemberTypes.Property:
                return ((PropertyInfo) @this).GetDeclaraction();
            case MemberTypes.Constructor:
                return ((ConstructorInfo) @this).GetDeclaraction();
            case MemberTypes.Method:
                return ((MethodInfo) @this).GetDeclaraction();
            case MemberTypes.TypeInfo:
                return ((Type) @this).GetDeclaraction();
            case MemberTypes.NestedType:
                return ((Type) @this).GetDeclaraction();
            case MemberTypes.Event:
                return ((EventInfo) @this).GetDeclaraction();
                return null;