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('.')); } }