Created
May 24, 2013 13:34
-
-
Save vendettamit/5643544 to your computer and use it in GitHub Desktop.
Reflection miscelleneous
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> | |
/// Gets the error message attribute. | |
/// </summary> | |
/// <param name="memberName">Name of the member.</param> | |
/// <returns> | |
/// value of attribute from class | |
/// </returns> | |
public static string GetErrorMessageAttributeValue(string memberName) | |
{ | |
string message = string.Empty; | |
MemberInfo memberInfo = typeof(RegexValues).GetMember(memberName).FirstOrDefault(); | |
if (memberInfo != null) | |
{ | |
message = memberInfo.GetCustomAttributes().Where( | |
x => (x is ErrorMessageAttribute)).Select(x => ((ErrorMessageAttribute)x).GetMessage()).FirstOrDefault(); | |
} | |
return message; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment