Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow commands with no parameters to compile #20

Merged
merged 1 commit into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions samples/Console/TestCommands/HelloWorldCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,13 @@ public ValueTask<ICommandResult> HelloWorldCommand(

return new ValueTask<ICommandResult>(new NoContentCommandResult());
}

[Command("code")]
public ValueTask<ICommandResult> HelloCodeCommand()
{
_logger.LogInformation("Hello code from HelloModule!");

return new ValueTask<ICommandResult>(new NoContentCommandResult());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ var parameterNamespaces
.Select(
x => $"new CommandFactory__{@class.Name}__{method.Name}__{x.Name}()"));

var parameterArray = parameterTypes == string.Empty
? "Array.Empty<IParameter>()"
: $@"new IParameter[]
{{
{parameterTypes}
}}";

var parameterAccessors = string.Join(", ",
method.Parameters
.Select(
Expand All @@ -97,6 +104,13 @@ var parameterNamespaces
method.Parameters
.Select(x => $"typeof({x.ToDisplayString()})"));

var reflectionArray = reflectionTypes == string.Empty
? "types: Array.Empty<Type>()"
: $@"types: new[]
{{
{reflectionTypes}
}}";

return
$@"{namespaces}

Expand All @@ -118,21 +132,15 @@ private static readonly MethodInfo Method
bindingAttr: {GetBindingFlags(method)},
binder: default,
callConvention: {GetCallConv(method)},
types: new[]
{{
{reflectionTypes}
}},
{reflectionArray},
modifiers: null)!;

private IReadOnlyDictionary<object, object?>? _data;

public CommandString Name {{ get; }} = {commandPath};

public IReadOnlyList<IParameter> Parameters {{ get; }}
= new IParameter[]
{{
{parameterTypes}
}};
= {parameterArray};

public IReadOnlyDictionary<object, object?> Data
{{
Expand Down