using Console.Waterworks.Core.Attributes; using Console.Waterworks.Core.Loggers; using System; using System.Collections.Generic; using System.Reflection; namespace Console.Waterworks.Core.Specialists { class HelpSpecialist { CW_Logger _logger = new CW_Logger(); internal MemberInfo[] GetCommandMembers(List commandClasses) => commandClasses[0].GetMembers(); internal bool ListCommand(MemberInfo command) { var customAttributes = GetCustomAttributes(command); var castedAttributes = CheckForAttributesType(customAttributes); return (castedAttributes != null) ? castedAttributes.ShowCommand : false; } T CheckForAttributesType(object[] attributes) { T theAttributes = default(T); for (int i = 0; i < attributes.Length; i++) { try { theAttributes = (T)attributes[i]; break; } catch (Exception) { _logger.LogInfoMessage("The attempted casting attempt failed. Do not panic. This was expected"); } } return theAttributes; } object[] GetCustomAttributes(MemberInfo command) => command.GetCustomAttributes(true) as object[]; internal object GetParametres(MemberInfo command) { var attributes = GetCustomAttributes(command); var castedAttributes = CheckForAttributesType(attributes); return (castedAttributes != null) ? castedAttributes.Parameters : "Parameters values could not be found"; } internal object GetDescription(MemberInfo command) { var attributes = GetCustomAttributes(command); var castedAttributes = CheckForAttributesType(attributes); return (castedAttributes != null) ? castedAttributes.Description : "Description could not be found"; } internal object GetUsageExamples(MemberInfo command) { var attributes = GetCustomAttributes(command); var castedAttributes = CheckForAttributesType(attributes); return (castedAttributes != null) ? castedAttributes.UsageExample : "Example could not be found"; } } }