|
|
|
using Console.Waterworks.Attributes;
|
|
|
|
using Console.Waterworks.Loggers;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
namespace Console.Waterworks.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);
|
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|