MemberInfo - GetSignature

A MemberInfo extension method that gets a signature.

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 - GetSignature

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 GetSignature(this MemberInfo @this)
        switch (@this.MemberType)
            case MemberTypes.Field:
                return ((FieldInfo) @this).GetSignature();
            case MemberTypes.Property:
                return ((PropertyInfo) @this).GetSignature();
            case MemberTypes.Constructor:
                return ((ConstructorInfo) @this).GetSignature();
            case MemberTypes.Method:
                return ((MethodInfo) @this).GetSignature();
            case MemberTypes.TypeInfo:
                return ((Type) @this).GetSignature();
            case MemberTypes.NestedType:
                return ((Type) @this).GetSignature();
            case MemberTypes.Event:
                return ((EventInfo) @this).GetSignature();
                return null;