Beispiel #1
0
 internal FlagDefinition(CallFlagAttribute attribute, ParameterInfo param)
 {
     if (!param.HasDefaultValue)
     {
         throw new ArgumentException($"The parameter {param} does not have a default value.");
     }
     DefaultValue  = param.DefaultValue;
     ShortKey      = attribute.ShortKey;
     LongKey       = attribute.LongKey;
     Description   = attribute.Description;
     Type          = param.ParameterType;
     RequiresInput = Type != typeof(bool);
     Parameter     = param;
     ParamName     = NameAttribute.GetFor(param);
 }
Beispiel #2
0
 private ArgumentInfo(ParameterInfo parameter, CallInfo call, bool useDefault)
 {
     Parameter       = parameter;
     UseDefault      = useDefault;
     IsDense         = DenseAttribute.ExistsOn(parameter);
     Type            = Parameter.ParameterType;
     DefaultValue    = Parameter.DefaultValue;
     IsRawArgument   = RawArgumentsAttribute.ExistsOn(parameter);
     HasDefaultValue = Parameter.HasDefaultValue;
     Name            = NameAttribute.GetFor(Parameter);
     Parent          = call;
     Flag            = CallFlagAttribute.GetFor(Parameter);
     if (IsDense && Flag != null)
     {
         throw new InvalidOperationException("Cannot have a dense flag parameter");
     }
 }
Beispiel #3
0
 private CommandInfo(Type type)
 {
     if (!type.IsSubclassOf(typeof(Command)))
     {
         throw new InvalidOperationException($"Cannot create CommandInfo from {type}");
     }
     CommandType        = type;
     Group              = GroupAttribute.GetFor(type);
     Name               = NameAttribute.GetFor(type);
     Alias              = AliasAttribute.GetFor(type);
     Description        = DescriptionAttribute.GetFor(type);
     DefaultPermissions = DefaultPermissionAttribute.GetPermFor(type);
     RequiredContexts   = RequireContextAttribute.GetFor(type);
     PermissionKey      = DefaultPermissionAttribute.GetKeyFor(type);
     Note               = NotesAttribute.GetFor(type);
     RequireOwner       = RequireOwnerAttribute.ExistsOn(type);
     RequireGuild       = RequireGuildAttribute.GetFor(type);
     Hidden             = false;
     Calls              = null;
     Calls              = CallInfo.BuildFrom(this).ToList().AsReadOnly();
     Hidden             = HiddenAttribute.ExistsOn(type) || Calls.All(c => c.Hidden);
 }
 public static string GetKeyFor(Type info)
 => info.GetCustomAttribute <DefaultPermissionAttribute>()?.PermissionKey ?? NameAttribute.GetFor(info);