Skip to content

Instantly share code, notes, and snippets.

@krlm
Last active December 19, 2015 22:38
Show Gist options
  • Save krlm/6028348 to your computer and use it in GitHub Desktop.
Save krlm/6028348 to your computer and use it in GitHub Desktop.
Custom attribute access from FastMember Member class
/// <summary>
/// Represents an abstracted view of an individual member defined for a type
/// </summary>
public sealed class Member
{
private readonly MemberInfo member;
private readonly static ConcurrentDictionary<MemberInfo, object> attributeLookup = new ConcurrentDictionary<MemberInfo, object>();
/// <summary>
/// Provides an access to the custom attribute of Member
/// </summary>
public object GetCustomAttribute(Type attributeType)
{
if(IsDefined(attributeType))
{
return attributeLookup.GetOrAdd(member, m => Attribute.GetCustomAttribute(m, attributeType));
}
throw new InvalidOperationException("Attribute is not defined");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment