[Fix] Include section accessories in ComponentCount() (#3126)
This commit is contained in:
@@ -9,10 +9,21 @@ public static class ComponentContainerExtensions
|
|||||||
/// Gets the total number of components in this and all child <see cref="IComponentContainer"/>s combined.
|
/// Gets the total number of components in this and all child <see cref="IComponentContainer"/>s combined.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static int ComponentCount(this IComponentContainer container)
|
public static int ComponentCount(this IComponentContainer container)
|
||||||
=> (container.Components?.Count ?? 0)
|
{
|
||||||
+ container.Components?
|
var sum = 0;
|
||||||
.OfType<IComponentContainer>()
|
foreach (var component in container.Components)
|
||||||
.Sum(x => x.ComponentCount()) ?? 0;
|
{
|
||||||
|
sum++;
|
||||||
|
|
||||||
|
if (component is SectionBuilder { Accessory: not null })
|
||||||
|
sum++;
|
||||||
|
|
||||||
|
if (component is IComponentContainer childContainer)
|
||||||
|
sum += childContainer.ComponentCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a <see cref="TextDisplayBuilder"/> to the container.
|
/// Adds a <see cref="TextDisplayBuilder"/> to the container.
|
||||||
|
|||||||
Reference in New Issue
Block a user