private static string GetMessageText(ReturnCode returnCode) { string enumName = Enum.GetName(returnCode.GetType(), returnCode); string resourceName = string.Format("ReturnCode{0}", enumName); string message = Resources.ResourceManager.GetString(resourceName); if (string.IsNullOrEmpty(message)) { message = enumName; } return message; }
/// <summary> /// Gets the resx key defined in the <see cref="ResxKeyAttribute"/> on the provided <see cref="ReturnCode"/> /// </summary> /// <param name="code">The <see cref="ReturnCode"/></param> /// <returns>The resx key associated with this <see cref="ReturnCode"/></returns> public static string GetResxKey(this ReturnCode code) { string key = null; Type t = code.GetType(); MemberInfo[] members = t.GetMember(code.ToString()); if (members.Length == 1) { object[] attrs = members[0].GetCustomAttributes(typeof(ResxKeyAttribute), false); if (attrs.Length == 1) { key = ((ResxKeyAttribute)attrs[0]).Key; } } return(key); }