Get member attribute
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
public class Util
{
public static T GetAttribute<T>(MemberInfo info) where T : class
{
return Attribute.GetCustomAttribute(info, typeof(T), false) as T;
}
public static IQueryable<T> GetAttributes<T>(MemberInfo info) where T : System.Attribute
{
List<T> items = new List<T>();
foreach (T attrib in Attribute.GetCustomAttributes(info, typeof(T), false))
{
items.Add(attrib);
}
return items.AsQueryable<T>();
}
}
Related examples in the same category