fix NRE introduced in 3.17.3 (#3101)

This commit is contained in:
Mihail Gribkov
2025-04-27 00:14:36 +03:00
committed by GitHub
parent d27bb49b2d
commit ec0621a264
6 changed files with 61 additions and 21 deletions

View File

@@ -21,8 +21,12 @@ namespace Discord
get => _name; get => _name;
set set
{ {
Preconditions.AtLeast(value.Length, 1, nameof(Name)); if (value is not null)
Preconditions.AtMost(value.Length, 100, nameof(Name)); {
Preconditions.AtLeast(value.Length, 1, nameof(Name));
Preconditions.AtMost(value.Length, 100, nameof(Name));
}
_name = value; _name = value;
} }
} }
@@ -38,7 +42,7 @@ namespace Discord
get => _value; get => _value;
set set
{ {
if (value != null && value is not string && !value.IsNumericType()) if (value is not null && value is not string && !value.IsNumericType())
throw new ArgumentException($"The value of a choice must be a string or a numeric type! Value: \"{value}\""); throw new ArgumentException($"The value of a choice must be a string or a numeric type! Value: \"{value}\"");
_value = value; _value = value;
} }

View File

@@ -24,8 +24,12 @@ public class ButtonBuilder
get => _label; get => _label;
set set
{ {
Preconditions.AtLeast(value.Length, 1, nameof(Label)); if (value is not null)
Preconditions.AtMost(value.Length, MaxButtonLabelLength, nameof(Label)); {
Preconditions.AtLeast(value.Length, 1, nameof(Label));
Preconditions.AtMost(value.Length, MaxButtonLabelLength, nameof(Label));
}
_label = value; _label = value;
} }
} }
@@ -40,8 +44,12 @@ public class ButtonBuilder
get => _customId; get => _customId;
set set
{ {
Preconditions.AtLeast(value.Length, 1, nameof(CustomId)); if (value is not null)
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId)); {
Preconditions.AtLeast(value.Length, 1, nameof(CustomId));
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId));
}
_customId = value; _customId = value;
} }
} }

View File

@@ -35,8 +35,12 @@ public class SelectMenuBuilder
get => _customId; get => _customId;
set set
{ {
Preconditions.AtLeast(value.Length, 1, nameof(CustomId)); if (value is not null)
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId)); {
Preconditions.AtLeast(value.Length, 1, nameof(CustomId));
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId));
}
_customId = value; _customId = value;
} }
} }
@@ -63,8 +67,12 @@ public class SelectMenuBuilder
get => _placeholder; get => _placeholder;
set set
{ {
Preconditions.AtLeast(value.Length, 1, nameof(Placeholder)); if (value is not null)
Preconditions.AtMost(value.Length, MaxPlaceholderLength, nameof(Placeholder)); {
Preconditions.AtLeast(value.Length, 1, nameof(Placeholder));
Preconditions.AtMost(value.Length, MaxPlaceholderLength, nameof(Placeholder));
}
_placeholder = value; _placeholder = value;
} }
} }

View File

@@ -32,8 +32,12 @@ public class SelectMenuOptionBuilder
get => _label; get => _label;
set set
{ {
Preconditions.AtLeast(value.Length, 1, nameof(Label)); if (value is not null)
Preconditions.AtMost(value.Length, MaxSelectLabelLength, nameof(Label)); {
Preconditions.AtLeast(value.Length, 1, nameof(Label));
Preconditions.AtMost(value.Length, MaxSelectLabelLength, nameof(Label));
}
_label = value; _label = value;
} }
} }
@@ -48,8 +52,12 @@ public class SelectMenuOptionBuilder
get => _value; get => _value;
set set
{ {
Preconditions.AtLeast(value.Length, 1, nameof(Value)); if (value is not null)
Preconditions.AtMost(value.Length, MaxSelectValueLength, nameof(Value)); {
Preconditions.AtLeast(value.Length, 1, nameof(Value));
Preconditions.AtMost(value.Length, MaxSelectValueLength, nameof(Value));
}
_value = value; _value = value;
} }
} }
@@ -64,8 +72,12 @@ public class SelectMenuOptionBuilder
get => _description; get => _description;
set set
{ {
Preconditions.AtLeast(value.Length, 1, nameof(Description)); if (value is not null)
Preconditions.AtMost(value.Length, MaxDescriptionLength, nameof(Description)); {
Preconditions.AtLeast(value.Length, 1, nameof(Description));
Preconditions.AtMost(value.Length, MaxDescriptionLength, nameof(Description));
}
_description = value; _description = value;
} }
} }

View File

@@ -24,8 +24,12 @@ public class TextInputBuilder
get => _customId; get => _customId;
set set
{ {
Preconditions.AtLeast(value.Length, 1, nameof(CustomId)); if (value is not null)
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId)); {
Preconditions.AtLeast(value.Length, 1, nameof(CustomId));
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId));
}
_customId = value; _customId = value;
} }
} }

View File

@@ -40,8 +40,12 @@ namespace Discord
get => _customId; get => _customId;
set set
{ {
Preconditions.AtLeast(value.Length, 1, nameof(CustomId)); if (value is not null)
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId)); {
Preconditions.AtLeast(value.Length, 1, nameof(CustomId));
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId));
}
_customId = value; _customId = value;
} }
} }