File tree Expand file tree Collapse file tree
Code/MethodSystem/Methods/DictionaryMethods Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using SER . Code . ArgumentSystem . Arguments ;
2+ using SER . Code . ArgumentSystem . BaseArguments ;
3+ using SER . Code . MethodSystem . BaseMethods . Synchronous ;
4+ using SER . Code . MethodSystem . Methods . DictionaryMethods . Structures ;
5+
6+ namespace SER . Code . MethodSystem . Methods . DictionaryMethods ;
7+
8+ [ UsedImplicitly ]
9+ // ReSharper disable once InconsistentNaming
10+ public class Dict_AddMethod : SynchronousMethod
11+ {
12+ public override string Description => "Adds a key-value pair to a dictionary." ;
13+
14+ public override Argument [ ] ExpectedArguments { get ; } =
15+ [
16+ new ReferenceArgument < Dict > ( "dictionary" ) ,
17+ new AnyValueArgument ( "key" ) ,
18+ new AnyValueArgument ( "value" )
19+ ] ;
20+
21+ public override void Execute ( )
22+ {
23+ Args . GetReference < Dict > ( "dictionary" ) . Add ( Args . GetAnyValue ( "key" ) , Args . GetAnyValue ( "value" ) ) ;
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ using SER . Code . ArgumentSystem . Arguments ;
2+ using SER . Code . ArgumentSystem . BaseArguments ;
3+ using SER . Code . MethodSystem . BaseMethods . Synchronous ;
4+ using SER . Code . MethodSystem . Methods . DictionaryMethods . Structures ;
5+ using SER . Code . ValueSystem ;
6+
7+ namespace SER . Code . MethodSystem . Methods . DictionaryMethods ;
8+
9+ [ UsedImplicitly ]
10+ // ReSharper disable once InconsistentNaming
11+ public class Dict_ContainsMethod : ReturningMethod < BoolValue >
12+ {
13+ public override string Description => "Returns true if the dictionary contains the provided key" ;
14+
15+ public override Argument [ ] ExpectedArguments { get ; } =
16+ [
17+ new ReferenceArgument < Dict > ( "dictionary" ) ,
18+ new AnyValueArgument ( "key" )
19+ ] ;
20+
21+ public override void Execute ( )
22+ {
23+ ReturnValue = Args . GetReference < Dict > ( "dictionary" ) . ContainsKey ( Args . GetAnyValue ( "key" ) ) ;
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ using SER . Code . ArgumentSystem . BaseArguments ;
2+ using SER . Code . MethodSystem . BaseMethods . Synchronous ;
3+ using SER . Code . MethodSystem . MethodDescriptors ;
4+ using SER . Code . MethodSystem . Methods . DictionaryMethods . Structures ;
5+
6+ namespace SER . Code . MethodSystem . Methods . DictionaryMethods ;
7+
8+ [ UsedImplicitly ]
9+ // ReSharper disable once InconsistentNaming
10+ public class Dict_EmptyMethod : ReferenceReturningMethod < Dict > , IAdditionalDescription
11+ {
12+ public override string Description => "Creates an empty dictionary." ;
13+
14+ public string AdditionalDescription =>
15+ "Dictionary is a collection of unique keys (values) mapped to specific values. " +
16+ "Think of it like a real-world dictionary where the \" word\" is the key and the \" definition\" is the value. " +
17+ "E.g. you can map the value \" hello\" to the \" world\" value. " +
18+ "This data type is used by more experienced users, allowing for dynamic data storage." ;
19+
20+ public override Argument [ ] ExpectedArguments { get ; } = [ ] ;
21+
22+ public override void Execute ( )
23+ {
24+ ReturnValue = new Dict ( ) ;
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ using SER . Code . ArgumentSystem . Arguments ;
2+ using SER . Code . ArgumentSystem . BaseArguments ;
3+ using SER . Code . Exceptions ;
4+ using SER . Code . MethodSystem . BaseMethods . Synchronous ;
5+ using SER . Code . MethodSystem . MethodDescriptors ;
6+ using SER . Code . MethodSystem . Methods . DictionaryMethods . Structures ;
7+ using SER . Code . ValueSystem . Other ;
8+
9+ namespace SER . Code . MethodSystem . Methods . DictionaryMethods ;
10+
11+ [ UsedImplicitly ]
12+ // ReSharper disable once InconsistentNaming
13+ public class Dict_GetMethod : ReturningMethod , ICanError
14+ {
15+ public override string Description => "Gets a value associated with a key from a dictionary." ;
16+
17+ public override TypeOfValue Returns => new UnknownTypeOfValue ( ) ;
18+
19+ public string [ ] ErrorReasons =>
20+ [
21+ "There is no key with the given name in the dictionary."
22+ ] ;
23+
24+ public override Argument [ ] ExpectedArguments { get ; } =
25+ [
26+ new ReferenceArgument < Dict > ( "dictionary" ) ,
27+ new AnyValueArgument ( "key" )
28+ ] ;
29+
30+ public override void Execute ( )
31+ {
32+ var dictionary = Args . GetReference < Dict > ( "dictionary" ) ;
33+ var key = Args . GetAnyValue ( "key" ) ;
34+
35+ if ( dictionary . TryGetValue ( key , out var value ) )
36+ {
37+ ReturnValue = value ;
38+ }
39+ else
40+ {
41+ throw new ScriptRuntimeError ( this , $ "Provided key '{ key } ' is not in the dictionary.") ;
42+ }
43+ }
44+ }
Original file line number Diff line number Diff line change 1+ using SER . Code . ArgumentSystem . Arguments ;
2+ using SER . Code . ArgumentSystem . BaseArguments ;
3+ using SER . Code . MethodSystem . BaseMethods . Synchronous ;
4+ using SER . Code . MethodSystem . Methods . DictionaryMethods . Structures ;
5+
6+ namespace SER . Code . MethodSystem . Methods . DictionaryMethods ;
7+
8+ [ UsedImplicitly ]
9+ // ReSharper disable once InconsistentNaming
10+ public class Dict_RemoveMethod : SynchronousMethod
11+ {
12+ public override string Description => "Removes a key-value pair from a dictionary." ;
13+
14+ public override Argument [ ] ExpectedArguments { get ; } =
15+ [
16+ new ReferenceArgument < Dict > ( "dictionary" ) ,
17+ new AnyValueArgument ( "key to remove" )
18+ ] ;
19+
20+ public override void Execute ( )
21+ {
22+ Args . GetReference < Dict > ( "dictionary" ) . Remove ( Args . GetAnyValue ( "key to remove" ) ) ;
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ using SER . Code . ValueSystem ;
2+
3+ namespace SER . Code . MethodSystem . Methods . DictionaryMethods . Structures ;
4+
5+ public class Dict : Dictionary < Value , Value > ;
You can’t perform that action at this time.
0 commit comments