Console.Waterworks.Core is the .Net Core version of Console.Waterworks.
https://www.craigoates.net/Software/project/8
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.4 KiB
63 lines
2.4 KiB
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<Type> commandClasses) => commandClasses[0].GetMembers(); |
|
|
|
internal bool ListCommand(MemberInfo command) |
|
{ |
|
var customAttributes = GetCustomAttributes(command); |
|
var castedAttributes = CheckForAttributesType<ListCommandAttribute>(customAttributes); |
|
return (castedAttributes != null) ? castedAttributes.ShowCommand : false; |
|
} |
|
|
|
T CheckForAttributesType<T>(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<ParametersAttribute>(attributes); |
|
return (castedAttributes != null) ? castedAttributes.Parameters : "Parameters values could not be found"; |
|
} |
|
|
|
internal object GetDescription(MemberInfo command) |
|
{ |
|
var attributes = GetCustomAttributes(command); |
|
var castedAttributes = CheckForAttributesType<DescriptionAttribute>(attributes); |
|
return (castedAttributes != null) ? castedAttributes.Description : "Description could not be found"; |
|
} |
|
|
|
internal object GetUsageExamples(MemberInfo command) |
|
{ |
|
var attributes = GetCustomAttributes(command); |
|
var castedAttributes = CheckForAttributesType<UsageAttribute>(attributes); |
|
return (castedAttributes != null) ? castedAttributes.UsageExample : "Example could not be found"; |
|
} |
|
} |
|
}
|
|
|