Skip to content

Commit 5181ef4

Browse files
add VariableArgument<T>
1 parent 4d587a8 commit 5181ef4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Code/ArgumentSystem/Arguments/VariableArgument.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using JetBrains.Annotations;
22
using SER.Code.ArgumentSystem.BaseArguments;
3+
using SER.Code.Helpers.Extensions;
34
using SER.Code.Helpers.ResultSystem;
45
using SER.Code.TokenSystem.Tokens;
56
using SER.Code.TokenSystem.Tokens.VariableTokens;
@@ -24,4 +25,23 @@ public DynamicTryGet<Variable> GetConvertSolution(BaseToken token)
2425

2526
return new(() => variableToken.TryGetVariable());
2627
}
28+
}
29+
30+
public class VariableArgument<T>(string name) : Argument(name) where T : Variable
31+
{
32+
public override string InputDescription => $"A {typeof(T).FriendlyTypeName()}";
33+
34+
[UsedImplicitly]
35+
public DynamicTryGet<T> GetConvertSolution(BaseToken token)
36+
{
37+
if (token is not VariableToken variableToken)
38+
{
39+
return $"Value '{token.RawRep}' is not a variable.";
40+
}
41+
42+
return new(() => variableToken
43+
.TryGetVariable()
44+
.SuccessTryCast<Variable, T>()
45+
);
46+
}
2747
}

Code/ArgumentSystem/ProvidedArguments.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public class ProvidedArguments(Method method)
2222
{
2323
private Dictionary<(string name, Type type), List<DynamicTryGet>> ArgumentValues { get; } = [];
2424

25+
public T GetVariable<T>(string argName) where T : Variable
26+
{
27+
return GetValue<T, VariableArgument<T>>(argName);
28+
}
29+
2530
public Database GetDatabase(string argName)
2631
{
2732
return GetValue<Database, DatabaseArgument>(argName);

0 commit comments

Comments
 (0)