using System.Reflection; namespace IStation.Epanet.Enums { public static class Error { public static string GetMsg(this ErrorCode errorCode) { FieldInfo field; Type t = typeof(ErrorCode); if (t.IsEnum && (field = t.GetField(errorCode.ToString())) != null && Attribute.GetCustomAttribute(field, typeof(ErrorAttribute)) is ErrorAttribute att && att.Msg != null) { return att.Msg; } return string.Empty; } } }