Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
feat(fx): allow empty param array parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdayo committed Jun 15, 2023
1 parent 7445748 commit 6f70ac5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Flandre.Framework/Common/CommandParameter.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
namespace Flandre.Framework.Common;

/// <summary>
/// 指令参数
/// </summary>
public sealed class CommandParameter
{
/// <summary>
/// 参数名称
/// </summary>
public string Name { get; }

/// <summary>
/// 参数类型
/// </summary>
public Type Type { get; }

/// <summary>
/// 参数默认值
/// </summary>
public object? DefaultValue { get; }

/// <summary>
/// 参数描述
/// </summary>
public string? Description { get; init; }

/// <summary>
/// 是否被 params 修饰
/// </summary>
public bool IsParamArray { get; }

/// <summary>
/// 是否为必须参数
/// </summary>
public bool IsRequired => DefaultValue is null;

internal CommandParameter(string name, Type type, object? defaultValue, bool isParamArray)
{
Name = name;
Type = type;
DefaultValue = defaultValue;
DefaultValue = isParamArray ? Array.CreateInstance(type.GetElementType()!, 0) : defaultValue;
IsParamArray = isParamArray;
}
}
3 changes: 3 additions & 0 deletions tests/Flandre.Framework.Tests/CommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public void TestArrayParameter()

var content = client.SendMessageForReply("test6 1.23 aaa bbb ccc ");
Assert.Equal("1.23 | aaa,bbb,ccc", content?.GetText());

content = client.SendMessageForReply("test6 2.34");
Assert.Equal("2.34 | ", content?.GetText());
}

[Fact]
Expand Down

0 comments on commit 6f70ac5

Please sign in to comment.