File tree Expand file tree Collapse file tree 8 files changed +26
-16
lines changed
Application/HydraScript.Application.CodeGeneration/Visitors
Domain/HydraScript.Domain.BackEnd/Impl/Instructions/WithAssignment/ExplicitCast
tests/HydraScript.UnitTests/Domain/BackEnd Expand file tree Collapse file tree 8 files changed +26
-16
lines changed Original file line number Diff line number Diff line change 55using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ComplexData . Create ;
66using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ComplexData . Read ;
77using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ComplexData . Write ;
8+ using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ExplicitCast ;
89using HydraScript . Domain . BackEnd . Impl . Instructions . WithJump ;
910using HydraScript . Domain . BackEnd . Impl . Values ;
1011using HydraScript . Domain . FrontEnd . Parser ;
Original file line number Diff line number Diff line change 22using HydraScript . Domain . BackEnd . Impl . Addresses ;
33using HydraScript . Domain . BackEnd . Impl . Instructions ;
44using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment ;
5+ using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ExplicitCast ;
56using HydraScript . Domain . BackEnd . Impl . Instructions . WithJump ;
67using HydraScript . Domain . Constants ;
78using HydraScript . Domain . FrontEnd . Parser ;
Original file line number Diff line number Diff line change 1+ namespace HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ExplicitCast ;
2+
3+ public abstract class AsInstruction < T > ( IValue value ) : Simple ( value )
4+ {
5+ protected override void Assign ( )
6+ {
7+ var value = Right . right ! . Get ( ) ;
8+ var valueAsType = value is T ? value : Convert ( value ) ;
9+ Left ? . Set ( valueAsType ) ;
10+ }
11+
12+ protected abstract T Convert ( object ? value ) ;
13+
14+ protected override string ToStringInternal ( ) =>
15+ $ "{ Left } = { Right . right } as { typeof ( T ) . Name } )";
16+ }
Original file line number Diff line number Diff line change 22using System . Text . Json ;
33using System . Text . Json . Serialization ;
44
5- namespace HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment ;
5+ namespace HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ExplicitCast ;
66
7- public partial class AsString ( IValue value ) : Simple ( value )
7+ public partial class AsString ( IValue value ) : AsInstruction < string > ( value )
88{
9- protected override void Assign ( )
10- {
11- var value = Right . right ! . Get ( ) ;
12- var valueAsString = value is string
13- ? value
14- : JsonSerializer . Serialize (
15- value : Right . right ! . Get ( ) ! ,
16- AsStringSerializationContext . Default . Object ) ;
17- Left ? . Set ( valueAsString ) ;
18- }
19-
20- protected override string ToStringInternal ( ) =>
21- $ "{ Left } = { Right . right } as string";
9+ protected override string Convert ( object ? value ) =>
10+ JsonSerializer . Serialize ( value , AsStringSerializationContext . Default . Object ) ;
2211
2312 [ JsonSourceGenerationOptions (
2413 GenerationMode = JsonSourceGenerationMode . Serialization ,
Original file line number Diff line number Diff line change 22using HydraScript . Domain . BackEnd . Impl . Addresses ;
33using HydraScript . Domain . BackEnd . Impl . Instructions ;
44using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment ;
5+ using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ExplicitCast ;
56using HydraScript . Domain . BackEnd . Impl . Values ;
67
78namespace HydraScript . UnitTests . Domain . BackEnd ;
Original file line number Diff line number Diff line change 11using HydraScript . Domain . BackEnd ;
2- using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment ;
32using HydraScript . Domain . BackEnd . Impl . Values ;
3+ using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ExplicitCast ;
44
55namespace HydraScript . UnitTests . Domain . BackEnd ;
66
Original file line number Diff line number Diff line change 44using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment ;
55using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ComplexData . Create ;
66using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ComplexData . Write ;
7+ using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ExplicitCast ;
78using HydraScript . Domain . BackEnd . Impl . Instructions . WithJump ;
89using HydraScript . Domain . BackEnd . Impl . Values ;
910
Original file line number Diff line number Diff line change 55using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment ;
66using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ComplexData . Create ;
77using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ComplexData . Write ;
8+ using HydraScript . Domain . BackEnd . Impl . Instructions . WithAssignment . ExplicitCast ;
89using HydraScript . Domain . BackEnd . Impl . Instructions . WithJump ;
910using HydraScript . Domain . BackEnd . Impl . Values ;
1011
You can’t perform that action at this time.
0 commit comments