Class ButtonElementBuilder
- Namespace
- Kook
- Assembly
- Kook.Net.Core.dll
An element builder to build a ButtonElement.
public class ButtonElementBuilder : IElementBuilder, IEquatable<ButtonElementBuilder>, IEquatable<IElementBuilder>
- Inheritance
-
ButtonElementBuilder
- Implements
- Inherited Members
Constructors
ButtonElementBuilder()
Initializes a new instance of the ButtonElementBuilder class.
public ButtonElementBuilder()
ButtonElementBuilder(string, ButtonTheme, string?, ButtonClickEventType)
Initializes a new instance of the ButtonElementBuilder class.
public ButtonElementBuilder(string text, ButtonTheme theme = ButtonTheme.Primary, string? value = null, ButtonClickEventType click = ButtonClickEventType.None)
Parameters
text
stringThe text of the button.
theme
ButtonThemeThe theme of the button.
value
stringThe value of the button.
click
ButtonClickEventTypeThe type of the click event.
Fields
MaxButtonTextLength
Gets the maximum button text length allowed by Kook.
public const int MaxButtonTextLength = 40
Field Value
Properties
Click
Gets or sets the type of the click event.
public ButtonClickEventType Click { get; set; }
Property Value
- ButtonClickEventType
A ButtonClickEventType that represents the type of the click event.
Text
Gets or sets the text element of the button.
public IElementBuilder? Text { get; set; }
Property Value
- IElementBuilder
An IElementBuilder that represents the text of the button.
Remarks
This property only takes a PlainTextElementBuilder or a KMarkdownElementBuilder.
Theme
Gets or sets the theme of the button.
public ButtonTheme Theme { get; set; }
Property Value
- ButtonTheme
A ButtonTheme that represents the theme of the button.
Type
Gets the type of the element that this builder builds.
public ElementType Type { get; }
Property Value
- ElementType
An ElementType that represents the type of element that this builder builds.
Value
Gets or sets the value of the button.
public string? Value { get; set; }
Property Value
- string
A string that represents the value of the button.
Remarks
If the Click is set to ReturnValue, the value of the property will be returned when the button is clicked.
Methods
Build()
Builds the ButtonElementBuilder into a ButtonElement.
public ButtonElement Build()
Returns
- ButtonElement
A ButtonElement represents the built element object.
Exceptions
- ArgumentException
The Text is neither a PlainTextElementBuilder nor a KMarkdownElementBuilder.
- ArgumentNullException
The Text is null.
- ArgumentException
The Text is empty.
- ArgumentException
The length of Text is greater than MaxButtonTextLength.
- ArgumentException
The Value of a button with a link event type is null or empty.
Equals(ButtonElementBuilder?)
Determines whether the specified ButtonElementBuilder is equal to the current ButtonElementBuilder.
public bool Equals(ButtonElementBuilder? buttonElementBuilder)
Parameters
buttonElementBuilder
ButtonElementBuilderThe ButtonElementBuilder to compare with the current ButtonElementBuilder.
Returns
- bool
true
if the specified ButtonElementBuilder is equal to the current ButtonElementBuilder; otherwise,false
.
Equals(object?)
Determines whether the specified object is equal to the current ButtonElementBuilder.
public override bool Equals(object? obj)
Parameters
obj
objectThe object to compare with the current ButtonElementBuilder.
Returns
- bool
true
if the specified object is equal to the current ButtonElementBuilder; otherwise,false
.
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
WithClick(ButtonClickEventType)
Sets the type of the event to be fired when the button is clicked in a ButtonElement.
public ButtonElementBuilder WithClick(ButtonClickEventType click)
Parameters
click
ButtonClickEventTypeThe type of the event to be fired when the button is clicked.
Returns
- ButtonElementBuilder
The current builder.
WithText(KMarkdownElementBuilder)
Sets the text of a ButtonElement.
public ButtonElementBuilder WithText(KMarkdownElementBuilder text)
Parameters
text
KMarkdownElementBuilderThe builder of a KMarkdownElement, which will be set as the text of the button.
Returns
- ButtonElementBuilder
The current builder.
WithText(PlainTextElementBuilder)
Sets the text of a ButtonElement.
public ButtonElementBuilder WithText(PlainTextElementBuilder text)
Parameters
text
PlainTextElementBuilderThe builder of a PlainTextElement, which will be set as the text of the button.
Returns
- ButtonElementBuilder
The current builder.
WithText(string, bool)
Sets the text of a ButtonElement.
public ButtonElementBuilder WithText(string text, bool isKMarkdown = false)
Parameters
text
stringA string to be set as the text of the button.
isKMarkdown
boolA bool indicating whether the text is in KMarkdown format; if
true
, the text will be set as a KMarkdownElement; iffalse
, the text will be set as a PlainTextElement.
Returns
- ButtonElementBuilder
The current builder.
WithText<T>(Action<T>)
Sets the text of a ButtonElement.
public ButtonElementBuilder WithText<T>(Action<T> action) where T : IElementBuilder, new()
Parameters
action
Action<T>The action to create a builder of an IElementBuilder, which will be set as the text of the button. The action must return a PlainTextElementBuilder or a KMarkdownElementBuilder.
Returns
- ButtonElementBuilder
The current builder.
Type Parameters
T
WithTheme(ButtonTheme)
Sets the theme of a ButtonElement.
public ButtonElementBuilder WithTheme(ButtonTheme theme)
Parameters
theme
ButtonThemeThe theme to be set.
Returns
- ButtonElementBuilder
The current builder.
WithValue(string?)
Sets the value of a ButtonElement.
public ButtonElementBuilder WithValue(string? value)
Parameters
value
stringThe value to be set.
Returns
- ButtonElementBuilder
The current builder.
Operators
operator ==(ButtonElementBuilder?, ButtonElementBuilder?)
Determines whether the specified ButtonElementBuilder is equal to the current ButtonElementBuilder.
public static bool operator ==(ButtonElementBuilder? left, ButtonElementBuilder? right)
Parameters
left
ButtonElementBuilderright
ButtonElementBuilder
Returns
- bool
true
if the specified ButtonElementBuilder is equal to the current ButtonElementBuilder; otherwise,false
.
operator !=(ButtonElementBuilder?, ButtonElementBuilder?)
Determines whether the specified ButtonElementBuilder is not equal to the current ButtonElementBuilder.
public static bool operator !=(ButtonElementBuilder? left, ButtonElementBuilder? right)
Parameters
left
ButtonElementBuilderright
ButtonElementBuilder
Returns
- bool
true
if the specified ButtonElementBuilder is not equal to the current ButtonElementBuilder; otherwise,false
.