Beispiel #1
0
        private CallInfo(MethodInfo method, CommandInfo info)
        {
            Method = method;
            if (!CallAttribute.ExistsOn(Method))
            {
                throw new InvalidOperationException($"Cannot create CallInfo from {Method} as it does not have the [Call] attribute");
            }
            Usage = UsageAttribute.GetFor(Method);
            DefaultPermissions = DefaultPermissionAttribute.GetPermFor(Method);
            PermissionKey      = DefaultPermissionAttribute.GetKeyFor(Method).ToLower();
            RequiredContexts   = RequireContextAttribute.GetFor(Method);
            RequireOwner       = RequireOwnerAttribute.ExistsOn(Method);
            ShowTyping         = !HideTypingAttribute.ExistsOn(Method);
            SubCall            = CallAttribute.GetFor(Method);
            Aliases            = AliasAttribute.GetFor(Method);
            Hidden             = HiddenAttribute.ExistsOn(Method);
            Parent             = info;
            Parameters         = null;
            Flags = null;
            ArgumentPermatations = null;

            var args = ArgumentInfo.BuildFrom(this);

            if (args.SkipWhile(p => p.Flag == null).Select(p => p.Flag).Contains(null))
            {
                throw new InvalidOperationException("All optional arguments after the first flag must also be flags");
            }
            Parameters           = args.TakeWhile(a => a.Flag == null).ToArray();
            Flags                = args.SkipWhile(a => a.Flag == null).Select(a => a.Flag).ToArray();
            ArgumentPermatations = ArgumentInfo.BuildPermetations(this).ToList().AsReadOnly();
        }
 public static string GetKeyFor(MethodInfo info)
 {
     if (info.GetCustomAttribute <DefaultPermissionAttribute>()?.PermissionKey != null)
     {
         return(GetKeyFor(info.DeclaringType) + ("." + info.GetCustomAttribute <DefaultPermissionAttribute>()?.PermissionKey ?? "").TrimEnd('.'));
     }
     else
     {
         return(GetKeyFor(info.DeclaringType) + ("." + CallAttribute.GetFor(info)).TrimEnd('.'));
     }
 }
Beispiel #3
0
 internal static IEnumerable <CallInfo> BuildFrom(CommandInfo info)
 {
     foreach (var method in info.CommandType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
              .Where(m => m.ReturnType == typeof(Task) && CallAttribute.ExistsOn(m) && !DoNotInstallAttribute.ExistsOn(m)))
     {
         var built = new CallInfo(method, info);
         if (built.ArgumentPermatations.Count == 0)
         {
             continue;
         }
         yield return(built);
     }
 }