private static void LoadCommandsFromMember(MemberInfo member, MethodInfo method) { IEnumerable <CommandAttribute> commandAttributes = member.GetCustomAttributes <CommandAttribute>(); CommandDescriptionAttribute descriptionAttribute = member.GetCustomAttribute <CommandDescriptionAttribute>(); foreach (CommandAttribute commandAttribute in commandAttributes) { if (!commandAttribute.Valid) { if (loggingLevel >= LoggingLevel.Warnings) { Debug.LogWarning($"Quantum Processor Warning: Could not add '{commandAttribute.Alias}' to the table as it is invalid."); } } else { CommandPlatformAttribute platformAttribute = member.GetCustomAttribute <CommandPlatformAttribute>(); Platform commandPlatforms = platformAttribute?.SupportedPlatforms ?? commandAttribute.SupportedPlatforms; if (commandPlatforms.HasFlag(Application.platform.ToPlatform())) { IEnumerable <CommandData> newCommands = CreateCommandOverloads(method, commandAttribute, descriptionAttribute); foreach (CommandData command in newCommands) { TryAddCommand(command); } } } } }
public CommandData(MethodInfo methodData, CommandAttribute commandAttribute, CommandDescriptionAttribute descriptionAttribute, int defaultParameterCount = 0) : this(methodData, commandAttribute, defaultParameterCount) { if ((descriptionAttribute?.Valid ?? false) && string.IsNullOrWhiteSpace(commandAttribute.Description)) { CommandDescription = descriptionAttribute.Description; } }
private static IEnumerable <CommandData> CreateCommandOverloads(MethodInfo method, CommandAttribute commandAttribute, CommandDescriptionAttribute descriptionAttribute) { int defaultParameters = method.GetParameters().Count((ParameterInfo x) => x.HasDefaultValue); for (int i = 0; i < defaultParameters + 1; i++) { CommandData command = new CommandData(method, commandAttribute, descriptionAttribute, i); yield return(command); } }