-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand.cs
More file actions
39 lines (29 loc) · 1.09 KB
/
Command.cs
File metadata and controls
39 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
namespace CommandMiddleware
{
using System;
using System.Reflection;
public abstract class Command
{
public Command(string name, bool? allowAnonymous = null, bool? rawResult = null)
{
this.Name = name;
if (rawResult.HasValue)
{
this.RawResult = rawResult.Value;
}
if (allowAnonymous.HasValue)
{
this.AllowAnonymous = allowAnonymous.Value;
}
}
public virtual string Name { get; }
public virtual bool RawResult { get; }
public virtual bool AllowAnonymous { get; }
public Type DtoModel => IsAsync() ? MethodInfo.ReturnType.GetGenericArguments()[0] : MethodInfo.ReturnType;
// TODO: ApplyInfo(MethodInfo)
protected abstract MethodInfo MethodInfo { get; }
public bool IsAsync() => typeof(Task).IsAssignableFrom(MethodInfo.ReturnType);
public ParameterInfo[] GetParameters() => MethodInfo.GetParameters();
public abstract object? Invoke(IServiceProvider container, object[] args);
}
}