Last active
December 19, 2015 22:38
-
-
Save krlm/6028348 to your computer and use it in GitHub Desktop.
Custom attribute access from FastMember Member class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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