Skip to content

Instantly share code, notes, and snippets.

@vendettamit
Created May 24, 2013 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vendettamit/5643544 to your computer and use it in GitHub Desktop.
Save vendettamit/5643544 to your computer and use it in GitHub Desktop.
Reflection miscelleneous
/// <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