private static Attribute[] GetAttributes(this RestartReasons restartReason) { var fi = restartReason.GetType().GetField(restartReason.ToString()); Attribute[] attributes = (Attribute[])fi.GetCustomAttributes(typeof(Attribute), false); return(attributes); }
public static string GetRestartCode(this RestartReasons restartReason) { Attribute[] attributes = restartReason.GetAttributes(); RestartReasonCodeAttribute attr = null; for (int i = 0; i < attributes.Length; i++) { if (attributes[i].GetType() == typeof(RestartReasonCodeAttribute)) { attr = (RestartReasonCodeAttribute)attributes[i]; break; } } if (attr == null) { return(restartReason.ToString()); } else { return(attr.RestartCode.ToString()); } }