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());
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Construct a new <see cref="EzoDeviceStatus"/> with provided informations
 /// </summary>
 /// <param name="restartCode">Resatart code (reason for restart)</param>
 /// <param name="vccVoltage">Voltage at Vcc [V]</param>
 public EzoDeviceStatus(RestartReasons restartCode, double vccVoltage)
 {
     RestartCode = restartCode;
     VccVoltage  = vccVoltage;
 }